Package org.jgrapht.graph.specifics
Class FastLookupUndirectedSpecifics<V,E>
- java.lang.Object
-
- org.jgrapht.graph.specifics.UndirectedSpecifics<V,E>
-
- org.jgrapht.graph.specifics.FastLookupUndirectedSpecifics<V,E>
-
- Type Parameters:
V
- the graph vertex typeE
- the graph edge type
- All Implemented Interfaces:
java.io.Serializable
,Specifics<V,E>
public class FastLookupUndirectedSpecifics<V,E> extends UndirectedSpecifics<V,E>
Fast implementation of UndirectedSpecifics. This class uses additional data structures to improve the performance of methods which depend on edge retrievals, e.g. getEdge(V u, V v), containsEdge(V u, V v),addEdge(V u, V v). A disadvantage is an increase in memory consumption. If memory utilization is an issue, use aDirectedSpecifics
instead.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static long
serialVersionUID
protected java.util.Map<Pair<V,V>,ArrayUnenforcedSet<E>>
touchingVerticesToEdgeMap
-
Fields inherited from class org.jgrapht.graph.specifics.UndirectedSpecifics
abstractBaseGraph, edgeSetFactory, vertexMapUndirected
-
-
Constructor Summary
Constructors Constructor Description FastLookupUndirectedSpecifics(AbstractBaseGraph<V,E> abstractBaseGraph)
Construct a new fast lookup undirected specifics.FastLookupUndirectedSpecifics(AbstractBaseGraph<V,E> abstractBaseGraph, java.util.Map<V,UndirectedEdgeContainer<V,E>> vertexMap)
Construct a new fast lookup undirected specifics.FastLookupUndirectedSpecifics(AbstractBaseGraph<V,E> abstractBaseGraph, java.util.Map<V,UndirectedEdgeContainer<V,E>> vertexMap, EdgeSetFactory<V,E> edgeSetFactory)
Construct a new fast lookup undirected specifics.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEdgeToTouchingVertices(E e)
Adds the specified edge to the edge containers of its source and target vertices.java.util.Set<E>
getAllEdges(V sourceVertex, V targetVertex)
Returns a set of all edges connecting source vertex to target vertex if such vertices exist in this graph.E
getEdge(V sourceVertex, V targetVertex)
Returns an edge connecting source vertex to target vertex if such vertices and such edge exist in this graph.void
removeEdgeFromTouchingVertices(E e)
Removes the specified edge from the edge containers of its source and target vertices.-
Methods inherited from class org.jgrapht.graph.specifics.UndirectedSpecifics
addVertex, degreeOf, edgesOf, getEdgeContainer, getVertexSet, incomingEdgesOf, inDegreeOf, outDegreeOf, outgoingEdgesOf
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
touchingVerticesToEdgeMap
protected java.util.Map<Pair<V,V>,ArrayUnenforcedSet<E>> touchingVerticesToEdgeMap
-
-
Constructor Detail
-
FastLookupUndirectedSpecifics
public FastLookupUndirectedSpecifics(AbstractBaseGraph<V,E> abstractBaseGraph)
Construct a new fast lookup undirected specifics.- Parameters:
abstractBaseGraph
- the graph for which these specifics are for
-
FastLookupUndirectedSpecifics
public FastLookupUndirectedSpecifics(AbstractBaseGraph<V,E> abstractBaseGraph, java.util.Map<V,UndirectedEdgeContainer<V,E>> vertexMap)
Construct a new fast lookup undirected specifics.- Parameters:
abstractBaseGraph
- the graph for which these specifics are forvertexMap
- map for the storage of vertex edge sets
-
FastLookupUndirectedSpecifics
public FastLookupUndirectedSpecifics(AbstractBaseGraph<V,E> abstractBaseGraph, java.util.Map<V,UndirectedEdgeContainer<V,E>> vertexMap, EdgeSetFactory<V,E> edgeSetFactory)
Construct a new fast lookup undirected specifics.- Parameters:
abstractBaseGraph
- the graph for which these specifics are forvertexMap
- map for the storage of vertex edge setsedgeSetFactory
- factory for the creation of vertex edge sets
-
-
Method Detail
-
getAllEdges
public java.util.Set<E> getAllEdges(V sourceVertex, V targetVertex)
Returns a set of all edges connecting source vertex to target vertex if such vertices exist in this graph. If any of the vertices does not exist or isnull
, returnsnull
. If both vertices exist but no edges found, returns an empty set.- Specified by:
getAllEdges
in interfaceSpecifics<V,E>
- Overrides:
getAllEdges
in classUndirectedSpecifics<V,E>
- Parameters:
sourceVertex
- source vertex of the edge.targetVertex
- target vertex of the edge.- Returns:
- a set of all edges connecting source vertex to target vertex.
-
getEdge
public E getEdge(V sourceVertex, V targetVertex)
Returns an edge connecting source vertex to target vertex if such vertices and such edge exist in this graph. Otherwise returnsnull
. If any of the specified vertices isnull
returnsnull
In undirected graphs, the returned edge may have its source and target vertices in the opposite order.
-
addEdgeToTouchingVertices
public void addEdgeToTouchingVertices(E e)
Adds the specified edge to the edge containers of its source and target vertices.- Specified by:
addEdgeToTouchingVertices
in interfaceSpecifics<V,E>
- Overrides:
addEdgeToTouchingVertices
in classUndirectedSpecifics<V,E>
- Parameters:
e
- the edge
-
removeEdgeFromTouchingVertices
public void removeEdgeFromTouchingVertices(E e)
Removes the specified edge from the edge containers of its source and target vertices.- Specified by:
removeEdgeFromTouchingVertices
in interfaceSpecifics<V,E>
- Overrides:
removeEdgeFromTouchingVertices
in classUndirectedSpecifics<V,E>
- Parameters:
e
- the edge
-
-