Undirected self-edges iterated twice

Jul 31, 2009 at 5:13 PM
Edited Jul 31, 2009 at 5:15 PM

UndirectedGraph.AdjacentEdges(TVertex vertex) iterates through all self-edges twice. One could argue that this is correct behavior, since it guarantees that the number of iterated edges matches the degree of the vertex. On the other hand, the name of the method implies that you're getting an enumerator of edges, not instances of edges meeting the vertex, so this could also be unexpected behavior. As it is, this creates a problem for anyone wanting to do a traversal of the graph's edges without double-counting (for the purpose of, say, drawing them). Using an EdgeDepthFirstSearch doesn't support UndirectedGraph and if it did would be somewhat inefficient. One approach is to pass an adjacentEdgeEnumerator to the DFS algorithm that filters out repeated edges. But this does not comply with the method documentation which says "All vertices[should be edges] passed to the method should be enumerated once and only once."

Either way, this should be included in the method documentation when it is written (which I am happy to help with, by the way).

Coordinator
Aug 1, 2009 at 4:00 PM

Good point. Adjacent edges should not enumerate self-edges twice.

Coordinator
Aug 1, 2009 at 4:01 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.