public BidirectionalGraph(
     bool allowParallelEdges,
     int capacity,
     Func <int, IVertexEdgeDictionary <TVertex, TEdge> > vertexEdgesDictionaryFactory)
 {
     Contract.Requires(vertexEdgesDictionaryFactory != null);
     this.allowParallelEdges = allowParallelEdges;
     this.vertexInEdges      = vertexEdgesDictionaryFactory(capacity);
     this.vertexOutEdges     = vertexEdgesDictionaryFactory(capacity);
 }
Exemple #2
0
 /// <summary>
 /// Constructor used during runtime serialization.
 /// </summary>
 protected UndirectedGraph(SerializationInfo info, StreamingContext context)
     : this((bool)info.GetValue("AllowParallelEdges", typeof(bool)))
 {
     EdgeCapacity   = (int)info.GetValue("EdgeCapacity", typeof(int));
     _adjacentEdges = (IVertexEdgeDictionary <TVertex, TEdge>)info.GetValue(
         "AdjacentEdges",
         typeof(IVertexEdgeDictionary <TVertex, TEdge>));
     _edges    = (IList <TEdge>)info.GetValue("Edges", typeof(IList <TEdge>));
     EdgeCount = _edges.Count;
 }
Exemple #3
0
        /// <summary>
        /// Copy constructor that creates sufficiently deep copy of the graph.
        /// </summary>
        /// <param name="other"></param>
        public BidirectionalGraph(BidirectionalGraph <TVertex, TEdge> other)
        {
            Contract.Requires(other != null);

            this.vertexInEdges      = other.vertexInEdges.Clone();
            this.vertexOutEdges     = other.vertexOutEdges.Clone();
            this.edgeCount          = other.edgeCount;
            this.edgeCapacity       = other.edgeCapacity;
            this.allowParallelEdges = other.allowParallelEdges;
        }
Exemple #4
0
 public AdjacencyGraph(
     bool allowParallelEdges,
     int capacity,
     int edgeCapacity,
     Func <int, IVertexEdgeDictionary <TVertex, TEdge> > vertexEdgesDictionaryFactory)
 {
     Contract.Requires(vertexEdgesDictionaryFactory != null);
     this.allowParallelEdges = allowParallelEdges;
     this.vertexEdges        = vertexEdgesDictionaryFactory(capacity);
     this.edgeCapacity       = edgeCapacity;
 }
        /// <summary>
        /// Copy constructor that creates sufficiently deep copy of the graph.
        /// </summary>
        /// <param name="other">Graph to copy.</param>
        public BidirectionalGraph([NotNull] BidirectionalGraph<TVertex, TEdge> other)
        {
            if (other is null)
                throw new ArgumentNullException(nameof(other));

            _vertexInEdges = other._vertexInEdges.Clone();
            _vertexOutEdges = other._vertexOutEdges.Clone();
            EdgeCount = other.EdgeCount;
            EdgeCapacity = other.EdgeCapacity;
            AllowParallelEdges = other.AllowParallelEdges;
        }
        /// <inheritdoc />
        public void Clear()
        {
            IVertexEdgeDictionary <TVertex, TEdge> vertexEdges = _vertexEdges;

            _vertexEdges = new VertexEdgeDictionary <TVertex, TEdge>();
            EdgeCount    = 0;

            NotifyEdgesRemoved(vertexEdges.SelectMany(edges => edges.Value).Distinct());
            NotifyVerticesRemoved(vertexEdges.Keys);
            vertexEdges.Clear();
        }
Exemple #7
0
 public AdjacencyGraph(bool allowParallelEdges, int capacity, int edgeCapacity)
 {
     this.allowParallelEdges = allowParallelEdges;
     if (capacity > -1)
     {
         this.vertexEdges = new VertexEdgeDictionary <TVertex, TEdge>(capacity);
     }
     else
     {
         this.vertexEdges = new VertexEdgeDictionary <TVertex, TEdge>();
     }
     this.edgeCapacity = edgeCapacity;
 }
Exemple #8
0
 public BidirectionalGraph(bool allowParallelEdges, int vertexCapacity)
 {
     this.allowParallelEdges = allowParallelEdges;
     if (vertexCapacity > -1)
     {
         this.vertexInEdges  = new VertexEdgeDictionary <TVertex, TEdge>(vertexCapacity);
         this.vertexOutEdges = new VertexEdgeDictionary <TVertex, TEdge>(vertexCapacity);
     }
     else
     {
         this.vertexInEdges  = new VertexEdgeDictionary <TVertex, TEdge>();
         this.vertexOutEdges = new VertexEdgeDictionary <TVertex, TEdge>();
     }
 }
Exemple #9
0
        private AdjacencyGraph(
            [NotNull] IVertexEdgeDictionary <TVertex, TEdge> vertexEdges,
            int edgeCount,
            int edgeCapacity,
            bool allowParallelEdges)
        {
            Debug.Assert(vertexEdges != null);
            Debug.Assert(edgeCount >= 0);

            _vertexEdges       = vertexEdges;
            EdgeCount          = edgeCount;
            EdgeCapacity       = edgeCapacity;
            AllowParallelEdges = allowParallelEdges;
        }
Exemple #10
0
        private AdjacencyGraph(
            IVertexEdgeDictionary <TVertex, TEdge> vertexEdges,
            int edgeCount,
            int edgeCapacity,
            bool allowParallelEdges
            )
        {
            Contract.Requires(vertexEdges != null);
            Contract.Requires(edgeCount >= 0);

            this.vertexEdges        = vertexEdges;
            this.edgeCount          = edgeCount;
            this.edgeCapacity       = edgeCapacity;
            this.allowParallelEdges = allowParallelEdges;
        }
        public AdjacencyGraph(bool allowParallelEdges, int vertexCapacity, int edgeCapacity, IEqualityComparer <TVertex> vertexComparer)
        {
            //Contract.Requires(vertexComparer != null);

            this.allowParallelEdges = allowParallelEdges;
            if (vertexCapacity > -1)
            {
                this.vertexEdges = new VertexEdgeDictionary <TVertex, TEdge>(vertexCapacity, vertexComparer);
            }
            else
            {
                this.vertexEdges = new VertexEdgeDictionary <TVertex, TEdge>(vertexComparer);
            }
            this.edgeCapacity = edgeCapacity;
        }
        /// <inheritdoc />
        public void Clear()
        {
            IList <TEdge> edges = _edges;

            _edges = new List <TEdge>();
            IVertexEdgeDictionary <TVertex, TEdge> adjacentEdges = _adjacentEdges;

            _adjacentEdges = new VertexEdgeDictionary <TVertex, TEdge>();
            EdgeCount      = 0;

            NotifyEdgesRemoved(edges);
            NotifyVerticesRemoved(adjacentEdges.Keys);
            edges.Clear();
            adjacentEdges.Clear();
        }
        private UndirectedGraph(
            IList <TEdge> edges,
            IVertexEdgeDictionary <TVertex, TEdge> adjacentEdges,
            EdgeEqualityComparer <TVertex> edgeEqualityComparer,
            int edgeCapacity,
            bool allowParallelEdges)
            : this(allowParallelEdges, edgeEqualityComparer)
        {
            Debug.Assert(edges != null);
            Debug.Assert(adjacentEdges != null);

            _edges         = edges;
            _adjacentEdges = adjacentEdges;
            EdgeCount      = edges.Count;
            EdgeCapacity   = edgeCapacity;
        }
        private BidirectionalGraph(
            IVertexEdgeDictionary <TVertex, TEdge> vertexInEdges,
            IVertexEdgeDictionary <TVertex, TEdge> vertexOutEdges,
            int edgeCount,
            int edgeCapacity,
            bool allowParallelEdges
            )
        {
            //Contract.Requires(vertexInEdges != null);
            //Contract.Requires(vertexOutEdges != null);
            //Contract.Requires(edgeCount >= 0);

            this.vertexInEdges      = vertexInEdges;
            this.vertexOutEdges     = vertexOutEdges;
            this.edgeCount          = edgeCount;
            this.edgeCapacity       = edgeCapacity;
            this.allowParallelEdges = allowParallelEdges;
        }