// Return the existing edge for the input vertexes. // If no add a new edge to the graph. private void AddEdge(GraphVertex startVertex, GraphVertex endVertex) { // Quickly check if (startVertex.GetSuccessorEdges().Count == 0 || endVertex.GetPredecessorEdges().Count == 0) { GraphEdge edge = new GraphEdge(startVertex, endVertex); m_NodeGraphEdgeList.Add(edge); return; } // Just need to check one vertex FRList<GraphEdge> sucessorGraphEdges = startVertex.GetSuccessorEdges(); foreach (GraphEdge edge in sucessorGraphEdges) { if (edge.GetEndVertex() == endVertex) return; // Do nothing if it exists. } // Add a new edge GraphEdge edge2 = new GraphEdge(startVertex, endVertex); m_NodeGraphEdgeList.Add(edge2); }
public void AddSuccessor(GraphEdge edge) { // We don't check whether the edge is valid or // Whether it already exits. // The caller should make sure the input edge // is valid and not exists. m_SucessorGraphEdges.Add(edge); }