Exemplo n.º 1
0
        private void RemoveInEdges([NotNull, InstantHandle] Predicate <TVertex> shouldRemove)
        {
            Debug.Assert(shouldRemove != null);

            // Run over edges and remove each edge touching the vertices to remove
            foreach (IEdgeList <TVertex, TEdge> outEdges in _vertexEdges.Select(pair => pair.Value))
            {
                // Collect indexes of edges to remove
                var indexesToRemove = new List <int>();
                var edgesToRemove   = new List <TEdge>();
                for (int i = 0; i < outEdges.Count; ++i)
                {
                    TEdge outEdge = outEdges[i];
                    if (shouldRemove(outEdge.Target))
                    {
                        indexesToRemove.Add(i);
                        edgesToRemove.Add(outEdge);
                    }
                }

                // Remove collected edges
                for (int i = indexesToRemove.Count - 1; i >= 0; --i)
                {
                    outEdges.RemoveAt(indexesToRemove[i]);
                }

                EdgeCount -= indexesToRemove.Count;
                Debug.Assert(EdgeCount >= 0);
                NotifyEdgesRemoved(edgesToRemove);
            }
        }