Reputation: 60
I would like to make a simple graph which is a graph without node's selfloop. In tutorial that is avaiable online it is said that I should use SimpleGraph interface, however it isn't working as it is not found in any jar. Is there something I can do to disable selflooping or should I just for ex. at every mousekey release check if any selfloops are being added and delete such edge which would be highly inefficient.
Upvotes: 0
Views: 152
Reputation: 40
As said in above point no. 3 your code should look like that:
public class UndirectedSimpleGraph<V,E> extends UndirectedSparseGraph<V,E> {
public UndirectedSimpleGraph(){
super();
}
public boolean addEdge(E edge, Pair<? extends V> endpoints, EdgeType edgeType){
Pair<V> new_endpoints = getValidatedEndpoints(edge, endpoints);
if (new_endpoints == null)
return false;
V v1 = new_endpoints.getFirst();
V v2 = new_endpoints.getSecond();
if(v1.equals(v2))
return false;
else
return super.addEdge(edge,endpoints,edgeType);
}
Upvotes: 1
Reputation: 2704
I don't know what tutorial that is, but JUNG has no "SimpleGraph" interface.
You can trivially accomplish this yourself, however, via one of these mechanisms:
I don't see why you think this is inefficient; any of these checks are O(1).
Upvotes: 0