public RemoveVertexResult <TVertex, TEdge> RemoveVertex(TVertex vertex)
        {
            bool vertexWasRemoved;

            TEdge[] edgesOfRemovedVertex;

            lock (SyncRoot)
            {
                edgesOfRemovedVertex = Graph.GetAllEdges(vertex).ToArray();
                vertexWasRemoved     = Graph.RemoveVertex(vertex);
            }

            if (!vertexWasRemoved)
            {
                return(RemoveVertexResult <TVertex, TEdge> .Empty);
            }

            foreach (var edge in edgesOfRemovedVertex)
            {
                EdgeRemoved?.Invoke(edge);
            }

            VertexRemoved?.Invoke(vertex);

            return(new RemoveVertexResult <TVertex, TEdge>(vertex, edgesOfRemovedVertex));
        }
        /// <summary>
        /// Called for each removed vertex.
        /// </summary>
        /// <param name="vertex">Removed vertex.</param>
        protected virtual void OnVertexRemoved([NotNull] TVertex vertex)
        {
            if (vertex == null)
            {
                throw new ArgumentNullException(nameof(vertex));
            }

            VertexRemoved?.Invoke(vertex);
        }
Beispiel #3
0
        /// <summary>
        /// Removes vertex from the list of digraph vertices
        /// </summary>
        /// <param name="index">Index of the vertex in the list</param>
        /// <exception cref="ArgumentOutOfRangeException"/>
        public void RemoveVertex(int index)
        {
            if (Vertices.Count <= index || index < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(index),
                                                      @"Index of the vertex must be a non-negative number less than the number of elements in the vertices list");
            }

            Arcs = Arcs.Where(arc => arc.StartVertex != index && arc.EndVertex != index).ToList();
            Arcs = Arcs.ConvertAll(arc =>
                                   new Arc(arc.StartVertex > index ? arc.StartVertex - 1 : arc.StartVertex,
                                           arc.EndVertex > index ? arc.EndVertex - 1 : arc.EndVertex));

            var removed = Vertices[index];

            Vertices.RemoveAt(index);
            Thresholds.RemoveAt(index);
            RefractoryPeriods.RemoveAt(index);
            State.RemoveAt(index);

            VertexRemoved?.Invoke(removed, new DigraphChangedEventArgs(index));
        }
        /// <summary>
        /// Called for each removed vertex.
        /// </summary>
        /// <param name="vertex">Removed vertex.</param>
        protected virtual void OnVertexRemoved(TVertex vertex)
        {
            Debug.Assert(vertex != null);

            VertexRemoved?.Invoke(vertex);
        }