Exemplo n.º 1
0
        public int RemoveOutEdgeIf(TVertex v, EdgePredicate <TVertex, TEdge> predicate)
        {
            GraphContracts.AssumeInVertexSet(this, v, "v");
            GraphContracts.AssumeNotNull(predicate, "predicate");

            var edges        = this.vertexEdges[v];
            var edgeToRemove = new EdgeList(edges.Count);

            foreach (var edge in edges)
            {
                if (predicate(edge))
                {
                    edgeToRemove.Add(edge);
                }
            }

            foreach (var edge in edgeToRemove)
            {
                edges.Remove(edge);
                this.OnEdgeRemoved(new EdgeEventArgs <TVertex, TEdge>(edge));
            }
            this.edgeCount -= edgeToRemove.Count;
            GraphContracts.Assert(this.edgeCount >= 0);

            return(edgeToRemove.Count);
        }
Exemplo n.º 2
0
        public void ClearInEdges(TVertex v)
        {
            GraphContracts.AssumeInVertexSet(this, v, "v");

            EdgeList inEdges = this.vertexInEdges[v];

            foreach (var edge in inEdges)
            {
                this.vertexOutEdges[edge.Source].Remove(edge);
                this.OnEdgeRemoved(new EdgeEventArgs <TVertex, TEdge>(edge));
            }

            this.edgeCount -= inEdges.Count;
            inEdges.Clear();
            GraphContracts.Assert(this.edgeCount >= 0);
        }
Exemplo n.º 3
0
        public virtual bool RemoveEdge(TEdge e)
        {
            GraphContracts.AssumeInVertexSet(this, e, "e");
            if (this.vertexOutEdges[e.Source].Remove(e))
            {
                this.vertexInEdges[e.Target].Remove(e);
                this.edgeCount--;
                GraphContracts.Assert(this.edgeCount >= 0);

                this.OnEdgeRemoved(new EdgeEventArgs <TVertex, TEdge>(e));
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        public void ClearOutEdges(TVertex v)
        {
            GraphContracts.AssumeInVertexSet(this, v, "v");

            var edges = this.vertexEdges[v];
            int count = edges.Count;

            if (this.EdgeRemoved != null) // call only if someone is listening
            {
                foreach (var edge in edges)
                {
                    this.OnEdgeRemoved(new EdgeEventArgs <TVertex, TEdge>(edge));
                }
            }
            edges.Clear();
            this.edgeCount -= count;
            GraphContracts.Assert(this.edgeCount >= 0);
        }
Exemplo n.º 5
0
        public virtual bool RemoveVertex(TVertex v)
        {
            GraphContracts.AssumeNotNull(v, "v");
            if (!this.ContainsVertex(v))
            {
                return(false);
            }

            // collect edges to remove
            EdgeList edgesToRemove = new EdgeList();

            foreach (var outEdge in this.OutEdges(v))
            {
                this.vertexInEdges[outEdge.Target].Remove(outEdge);
                edgesToRemove.Add(outEdge);
            }
            foreach (var inEdge in this.InEdges(v))
            {
                // might already have been removed
                if (this.vertexOutEdges[inEdge.Source].Remove(inEdge))
                {
                    edgesToRemove.Add(inEdge);
                }
            }

            // notify users
            if (this.EdgeRemoved != null)
            {
                foreach (TEdge edge in edgesToRemove)
                {
                    this.OnEdgeRemoved(new EdgeEventArgs <TVertex, TEdge>(edge));
                }
            }

            this.vertexOutEdges.Remove(v);
            this.vertexInEdges.Remove(v);
            this.edgeCount -= edgesToRemove.Count;
            this.OnVertexRemoved(new VertexEventArgs <TVertex>(v));

            GraphContracts.Assert(this.edgeCount >= 0);
            return(true);
        }
Exemplo n.º 6
0
        public int RemoveEdgeIf(EdgePredicate <TVertex, TEdge> predicate)
        {
            GraphContracts.AssumeNotNull(predicate, "predicate");

            var edges = new EdgeList();

            foreach (var edge in this.Edges)
            {
                if (predicate(edge))
                {
                    edges.Add(edge);
                }
            }

            foreach (var edge in edges)
            {
                this.RemoveEdge(edge);
            }

            GraphContracts.Assert(this.edgeCount >= 0);
            return(edges.Count);
        }