- java.lang.Object
- 
- org.jgrapht.graph.AbstractGraph<Integer,E>
- 
- org.jgrapht.sux4j.AbstractSuccinctGraph<E>
- 
- org.jgrapht.sux4j.AbstractSuccinctUndirectedGraph<it.unimi.dsi.fastutil.ints.IntIntSortedPair>
- 
- org.jgrapht.sux4j.SuccinctUndirectedGraph
 
 
 
 
- 
- All Implemented Interfaces:
- Serializable,- Graph<Integer,it.unimi.dsi.fastutil.ints.IntIntSortedPair>
 
 public class SuccinctUndirectedGraph extends AbstractSuccinctUndirectedGraph<it.unimi.dsi.fastutil.ints.IntIntSortedPair> implements Serializable An immutable undirected graph withIntIntSortedPairedges represented using quasi-succinct data structures.The graph representation of this implementation uses the Elias–Fano representation of monotone sequences to represent the positions of ones in the (linearized) adjacency matrix of the graph. Edges are represented by instances of IntIntSortedPair. Instances are serializable and thread safe.If the vertex set is compact (i.e., vertices are numbered from 0 consecutively), space usage will be close to the information-theoretical lower bound (typically, a few times smaller than a SparseIntUndirectedGraph).All accessors are very fast. Adjacency tests are very fast and happen in almost constant time. SuccinctIntUndirectedGraphis a much slower implementation with a similar footprint usingIntegeras edge type. Please read the class documentation for more information.For convenience, and as a compromise with the approach of SuccinctIntUndirectedGraph, this class provides methodsgetEdgeFromIndex()andgetIndexFromEdge()that map bijectively the edge set into a contiguous set of longs.- Author:
- Sebastiano Vigna
- See Also:
- SuccinctIntUndirectedGraph, Serialized Form
 
- 
- 
Nested Class Summary- 
Nested classes/interfaces inherited from class org.jgrapht.sux4j.AbstractSuccinctUndirectedGraphAbstractSuccinctUndirectedGraph.CumulativeDegrees<E>, AbstractSuccinctUndirectedGraph.CumulativeSuccessors<E>
 
- 
 - 
Field Summary- 
Fields inherited from class org.jgrapht.sux4j.AbstractSuccinctGraphm, n, sourceShift, targetMask, UNMODIFIABLE
 - 
Fields inherited from interface org.jgrapht.GraphDEFAULT_EDGE_WEIGHT
 
- 
 - 
Constructor SummaryConstructors Constructor Description SuccinctUndirectedGraph(int numVertices, List<Pair<Integer,Integer>> edges)Creates a new immutable succinct undirected graph from an edge list.SuccinctUndirectedGraph(Graph<Integer,E> graph)Creates a new immutable succinct undirected graph from a given undirected graph.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsEdge(it.unimi.dsi.fastutil.ints.IntIntSortedPair e)Returnstrueif this graph contains the specified edge.booleancontainsEdge(Integer sourceVertex, Integer targetVertex)Returnstrueif and only if this graph contains an edge going from the source vertex to the target vertex.intdegreeOf(Integer vertex)Returns the degree of the specified vertex.Set<it.unimi.dsi.fastutil.ints.IntIntSortedPair>edgeSet()Returns a set of the edges contained in this graph.Set<it.unimi.dsi.fastutil.ints.IntIntSortedPair>edgesOf(Integer vertex)Returns a set of all edges touching the specified vertex.it.unimi.dsi.fastutil.ints.IntIntSortedPairgetEdge(Integer sourceVertex, Integer targetVertex)Returns an edge connecting source vertex to target vertex if such vertices and such edge exist in this graph.it.unimi.dsi.fastutil.ints.IntIntSortedPairgetEdgeFromIndex(long i)Returns the edge with given index.IntegergetEdgeSource(it.unimi.dsi.fastutil.ints.IntIntSortedPair e)Returns the source vertex of an edge.IntegergetEdgeTarget(it.unimi.dsi.fastutil.ints.IntIntSortedPair e)Returns the target vertex of an edge.longgetIndexFromEdge(it.unimi.dsi.fastutil.ints.IntIntSortedPair e)Returns the index associated with the given edge.Set<it.unimi.dsi.fastutil.ints.IntIntSortedPair>incomingEdgesOf(Integer vertex)Returns a set of all edges incoming into the specified vertex.GraphIterables<Integer,it.unimi.dsi.fastutil.ints.IntIntSortedPair>iterables()Access the graph using theGraphIterablesinterface.Set<it.unimi.dsi.fastutil.ints.IntIntSortedPair>outgoingEdgesOf(Integer vertex)Returns a set of all edges outgoing from the specified vertex.- 
Methods inherited from class org.jgrapht.sux4j.AbstractSuccinctUndirectedGraphcontainsEdge, getType, inDegreeOf, outDegreeOf
 - 
Methods inherited from class org.jgrapht.sux4j.AbstractSuccinctGraphaddEdge, addEdge, addVertex, addVertex, assertVertexExist, containsVertex, getAllEdges, getEdgeSupplier, getEdgeWeight, getVertexSupplier, removeEdge, removeEdge, removeVertex, setEdgeWeight, vertexSet
 - 
Methods inherited from class org.jgrapht.graph.AbstractGraphequals, hashCode, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
 - 
Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface org.jgrapht.GraphsetEdgeWeight
 
- 
 
- 
- 
- 
Constructor Detail- 
SuccinctUndirectedGraphpublic SuccinctUndirectedGraph(Graph<Integer,E> graph) Creates a new immutable succinct undirected graph from a given undirected graph.- Type Parameters:
- E- the graph edge type
- Parameters:
- graph- an undirected graph: for good results, vertices should be numbered consecutively starting from 0.
 
 - 
SuccinctUndirectedGraphpublic SuccinctUndirectedGraph(int numVertices, List<Pair<Integer,Integer>> edges)Creates a new immutable succinct undirected graph from an edge list.This constructor just builds a SparseIntUndirectedGraphand delegates to the main constructor.- Parameters:
- numVertices- the number of vertices.
- edges- the edge list.
- See Also:
- SuccinctUndirectedGraph(Graph)
 
 
- 
 - 
Method Detail- 
containsEdgepublic boolean containsEdge(it.unimi.dsi.fastutil.ints.IntIntSortedPair e) Description copied from interface:GraphReturnstrueif this graph contains the specified edge. More formally, returnstrueif and only if this graph contains an edgee2such thate.equals(e2). If the specified edge isnullreturnsfalse.- Specified by:
- containsEdgein interface- Graph<Integer,it.unimi.dsi.fastutil.ints.IntIntSortedPair>
- Parameters:
- e- edge whose presence in this graph is to be tested.
- Returns:
- trueif this graph contains the specified edge.
 
 - 
edgeSetpublic Set<it.unimi.dsi.fastutil.ints.IntIntSortedPair> edgeSet() Description copied from interface:GraphReturns a set of the edges contained in this graph. The set is backed by the graph, so changes to the graph are reflected in the set. If the graph is modified while an iteration over the set is in progress, the results of the iteration are undefined.The graph implementation may maintain a particular set ordering (e.g. via LinkedHashSet) for deterministic iteration, but this is not required. It is the responsibility of callers who rely on this behavior to only use graph implementations which support it.
 - 
degreeOfpublic int degreeOf(Integer vertex) Description copied from interface:GraphReturns the degree of the specified vertex.A degree of a vertex in an undirected graph is the number of edges touching that vertex. Edges with same source and target vertices (self-loops) are counted twice. In directed graphs this method returns the sum of the "in degree" and the "out degree". 
 - 
edgesOfpublic Set<it.unimi.dsi.fastutil.ints.IntIntSortedPair> edgesOf(Integer vertex) Description copied from interface:GraphReturns a set of all edges touching the specified vertex. If no edges are touching the specified vertex returns an empty set.
 - 
incomingEdgesOfpublic Set<it.unimi.dsi.fastutil.ints.IntIntSortedPair> incomingEdgesOf(Integer vertex) Description copied from interface:GraphReturns a set of all edges incoming into the specified vertex.In the case of undirected graphs this method returns all edges touching the vertex, thus, some of the returned edges may have their source and target vertices in the opposite order. - Specified by:
- incomingEdgesOfin interface- Graph<Integer,it.unimi.dsi.fastutil.ints.IntIntSortedPair>
- Parameters:
- vertex- the vertex for which the list of incoming edges to be returned.
- Returns:
- a set of all edges incoming into the specified vertex.
 
 - 
outgoingEdgesOfpublic Set<it.unimi.dsi.fastutil.ints.IntIntSortedPair> outgoingEdgesOf(Integer vertex) Description copied from interface:GraphReturns a set of all edges outgoing from the specified vertex.In the case of undirected graphs this method returns all edges touching the vertex, thus, some of the returned edges may have their source and target vertices in the opposite order. - Specified by:
- outgoingEdgesOfin interface- Graph<Integer,it.unimi.dsi.fastutil.ints.IntIntSortedPair>
- Parameters:
- vertex- the vertex for which the list of outgoing edges to be returned.
- Returns:
- a set of all edges outgoing from the specified vertex.
 
 - 
getEdgeSourcepublic Integer getEdgeSource(it.unimi.dsi.fastutil.ints.IntIntSortedPair e) Description copied from interface:GraphReturns the source vertex of an edge. For an undirected graph, source and target are distinguishable designations (but without any mathematical meaning).- Specified by:
- getEdgeSourcein interface- Graph<Integer,it.unimi.dsi.fastutil.ints.IntIntSortedPair>
- Parameters:
- e- edge of interest
- Returns:
- source vertex
 
 - 
getEdgeTargetpublic Integer getEdgeTarget(it.unimi.dsi.fastutil.ints.IntIntSortedPair e) Description copied from interface:GraphReturns the target vertex of an edge. For an undirected graph, source and target are distinguishable designations (but without any mathematical meaning).- Specified by:
- getEdgeTargetin interface- Graph<Integer,it.unimi.dsi.fastutil.ints.IntIntSortedPair>
- Parameters:
- e- edge of interest
- Returns:
- target vertex
 
 - 
getIndexFromEdgepublic long getIndexFromEdge(it.unimi.dsi.fastutil.ints.IntIntSortedPair e) Returns the index associated with the given edge.- Parameters:
- e- an edge of the graph.
- Returns:
- the index associated with the edge, or −1 if the edge is not part of the graph.
- See Also:
- getEdgeFromIndex(long)
 
 - 
getEdgeFromIndexpublic it.unimi.dsi.fastutil.ints.IntIntSortedPair getEdgeFromIndex(long i) Returns the edge with given index.- Parameters:
- i- an index between 0 (included) and the number of edges (excluded).
- Returns:
- the pair with index i.
- See Also:
- getIndexFromEdge(IntIntSortedPair)
 
 - 
getEdgepublic it.unimi.dsi.fastutil.ints.IntIntSortedPair getEdge(Integer sourceVertex, Integer targetVertex) Description copied from interface:GraphReturns 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 isnullreturnsnullIn undirected graphs, the returned edge may have its source and target vertices in the opposite order. 
 - 
containsEdgepublic boolean containsEdge(Integer sourceVertex, Integer targetVertex) Description copied from interface:GraphReturnstrueif and only if this graph contains an edge going from the source vertex to the target vertex. In undirected graphs the same result is obtained when source and target are inverted. If any of the specified vertices does not exist in the graph, or if isnull, returnsfalse.- Specified by:
- containsEdgein interface- Graph<Integer,it.unimi.dsi.fastutil.ints.IntIntSortedPair>
- Overrides:
- containsEdgein class- AbstractGraph<Integer,it.unimi.dsi.fastutil.ints.IntIntSortedPair>
- Parameters:
- sourceVertex- source vertex of the edge.
- targetVertex- target vertex of the edge.
- Returns:
- trueif this graph contains the specified edge.
- See Also:
- Graph.containsEdge(Object, Object)
 
 - 
iterablespublic GraphIterables<Integer,it.unimi.dsi.fastutil.ints.IntIntSortedPair> iterables() Description copied from interface:GraphAccess the graph using theGraphIterablesinterface. This allows accessing graphs without the restrictions imposed by 32-bit arithmetic. Moreover, graph implementations are free to implement this interface without explicitly materializing intermediate results.
 
- 
 
-