Re: [jgrapht-users] Bug in removeAllEdges?
Brought to you by:
barak_naveh,
perfecthash
From: Trevor H. <tr...@vo...> - 2006-11-26 08:53:52
|
On Nov 25, 2006, at 10:49 PM, Trevor Harmon wrote: > But the following JGraphT program throws a > ConcurrentModificationException: > > DirectedGraph<String, DefaultEdge> g = > new DefaultDirectedGraph<String, DefaultEdge>(DefaultEdge.class); > String s1 = "s1"; > String s2 = "s2"; > g.addVertex(s1); > g.addVertex(s2); > g.addEdge(s1, s2); > g.edgesOf(s1).clear(); Oops, I don't think I tested this correctly. The above program doesn't throw an exception. In fact, it doesn't do anything. The graph remains unchanged! Also, replacing the edgesOf call with outgoingEdgesOf causes an UnsupportedOperationException. The latter may be acceptable behavior, but surely the former is not. And in any case, shouldn't there be some built-in way to remove all edges from a vertex? > Regardless of this problem, how is one supposed to remove all > outgoing edges from a vertex? So far, the best I've come up with is this: removeAllEdges( new Vector<Edge>(outgoingEdgesOf(node)) ); where "Edge" is the edge class and "node" is a vertex instance. Unfortunately, this requires allocating a temporary vector and copying every edge into it. Is there a more efficient way? Trevor |