AbstractBaseGraph#getEdge(V,V)
returns a single E. How does it decide which edge to return if the two vertices passed have more than one connecting edge?
Asked
Active
Viewed 105 times
1 Answers
0
If there are multiple edges, it looks like only one is returned:
public E getEdge(V sourceVertex, V targetVertex){
...
Iterator<E> iter =
getEdgeContainer(sourceVertex).vertexEdges.iterator();
while (iter.hasNext()) {
E e = iter.next();
...
The first legal edge (having source and target vertexes equal to the args) is returned. Since the iterator (based on a Map data structure) makes no gaurentee of the order that the components will be returned, it is not possible to be certain which edge will be returned. If you need to examine and choose a specific edge, you should probably use getAllEdges(V sourceVertex, V targetVertex)
.

Destruktor
- 463
- 1
- 4
- 19
-
So it iterates over all parallel edges and returns the last one it finds? Seems strange. Where did you find that block of code? I'd like to see the whole "while loop". – hendryau Jan 10 '14 at 15:18
-
1`org.jgrapht.graph.AbstractBaseGraph.UndirectedSpecifics.getEdge(V sourceVertex, V targetVertex)` – Destruktor Jan 10 '14 at 15:23