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); }
/// <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; }
/// <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; }
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(); }
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; }
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>(); } }
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; }
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; }