Clear() { AssertValid(); const String MethodName = "Clear"; // Do not just clear m_oLinkedList. This would remove the vertices // from the collection, but each vertex, which can continue to exist // after being removed from the graph, would still have a group of // incident edges that are no longer valid. foreach (IVertex oVertex in this) { // Tell the Vertex that it no longer has any incident edges or a // parent. Vertex oVertex2 = Vertex.IVertexToVertex( oVertex, this.ClassName, MethodName); oVertex2.FirstIncidentEdgeNode = null; oVertex2.SetParentGraph(null); } // Remove all vertices. m_oLinkedList.Clear(); // Remove all incident edges from all vertices. m_oParentGraph.Edges.Clear(); AssertValid(); }
Add ( IVertex vertex ) { AssertValid(); ArgumentChecker oArgumentChecker = this.ArgumentChecker; const String MethodName = "Add"; const String ArgumentName = "vertex"; oArgumentChecker.CheckArgumentNotNull( MethodName, ArgumentName, vertex); // Check whether the vertex already belongs to a graph. if (vertex.ParentGraph != null) { oArgumentChecker.ThrowArgumentException(MethodName, ArgumentName, "The vertex already belongs to a graph. A vertex can't be" + " added twice." ); } // The vertex is valid. Add it to the collection. m_oLinkedList.AddLast(vertex); // Set the vertex's parent graph. Vertex oVertex = Vertex.IVertexToVertex( vertex, this.ClassName, MethodName); oVertex.SetParentGraph(m_oParentGraph); // Fire a VertexAdded event if necessary. VertexEventHandler oVertexAdded = this.VertexAdded; if (oVertexAdded != null) { oVertexAdded(this, new VertexEventArgs(vertex)); } AssertValid(); }
Remove ( LinkedListNode <IVertex> oLinkedListNode ) { AssertValid(); Debug.Assert(oLinkedListNode != null); const String MethodName = "Remove"; // Cast to a Vertex. Vertex oVertex = Vertex.IVertexToVertex( oLinkedListNode.Value, this.ClassName, MethodName); // Remove the vertex's incident edges. oVertex.RemoveIncidentEdges(); // Now remove the node from the list. m_oLinkedList.Remove(oLinkedListNode); // The vertex no longer has a parent graph. oVertex.SetParentGraph(null); // Fire a VertexRemoved event if necessary. VertexEventHandler oVertexRemoved = this.VertexRemoved; if (oVertexRemoved != null) { oVertexRemoved(this, new VertexEventArgs(oVertex)); } AssertValid(); }