- java.lang.Object
-
- org.jgrapht.graph.AbstractGraph<java.lang.Integer,E>
-
- org.jgrapht.sux4j.AbstractSuccinctGraph<E>
-
- org.jgrapht.sux4j.AbstractSuccinctUndirectedGraph<java.lang.Integer>
-
- org.jgrapht.sux4j.SuccinctIntUndirectedGraph
-
- All Implemented Interfaces:
java.io.Serializable,Graph<java.lang.Integer,java.lang.Integer>
public class SuccinctIntUndirectedGraph extends AbstractSuccinctUndirectedGraph<java.lang.Integer> implements java.io.Serializable
An immutable undirected graph withIntegeredges represented using quasi-succinct data structures.The graph representation of this implementation is similar to that of
SparseIntDirectedGraph: nodes and edges are initial intervals of the natural numbers. Under the hood, however, this class uses the Elias–Fano representation of monotone sequences to represent the positions of ones in the (linearized) adjacency matrix of the graph. 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).Enumeration of edges is very slow. Adjacency tests are very fast and happen in almost constant time.
SuccinctUndirectedGraphis a much faster implementation with a similar footprint usingIntIntSortedPairas edge type. Please read the class documentation for more information.- See Also:
SuccinctUndirectedGraph, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classSuccinctIntUndirectedGraph.SuccinctGraphIterables-
Nested classes/interfaces inherited from class org.jgrapht.sux4j.AbstractSuccinctUndirectedGraph
AbstractSuccinctUndirectedGraph.CumulativeDegrees<E>, AbstractSuccinctUndirectedGraph.CumulativeSuccessors<E>
-
-
Field Summary
Fields Modifier and Type Field Description private it.unimi.dsi.sux4j.util.EliasFanoMonotoneLongBigListcumulativeIndegreesThe cumulative list of indegrees (number of edges in reversed order, including loops).private it.unimi.dsi.sux4j.util.EliasFanoIndexedMonotoneLongBigListcumulativeOutdegreesThe cumulative list of outdegrees (number of edges in sorted order, including loops).private SuccinctIntUndirectedGraph.SuccinctGraphIterablesiterablesprivate it.unimi.dsi.sux4j.util.EliasFanoMonotoneLongBigListpredecessorsThe cumulative list of predecessor (edges in reversed order, including loops) lists.private static longserialVersionUIDprivate it.unimi.dsi.sux4j.util.EliasFanoIndexedMonotoneLongBigListsuccessorsThe cumulative list of successor (edges in sorted order, including loops) lists.-
Fields inherited from class org.jgrapht.sux4j.AbstractSuccinctGraph
m, n, sourceShift, targetMask, UNMODIFIABLE
-
Fields inherited from interface org.jgrapht.Graph
DEFAULT_EDGE_WEIGHT
-
-
Constructor Summary
Constructors Constructor Description SuccinctIntUndirectedGraph(int numVertices, java.util.List<Pair<java.lang.Integer,java.lang.Integer>> edges)Creates a new immutable succinct undirected graph from an edge list.SuccinctIntUndirectedGraph(Graph<java.lang.Integer,E> graph)Creates a new immutable succinct undirected graph from a given undirected graph.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanassertEdgeExist(java.lang.Integer e)Ensures that the specified edge exists in this graph, or else throws exception.booleancontainsEdge(java.lang.Integer e)Returnstrueif this graph contains the specified edge.booleancontainsEdge(java.lang.Integer sourceVertex, java.lang.Integer targetVertex)Returnstrueif and only if this graph contains an edge going from the source vertex to the target vertex.intdegreeOf(java.lang.Integer vertex)Returns the degree of the specified vertex.java.util.Set<java.lang.Integer>edgeSet()Returns a set of the edges contained in this graph.it.unimi.dsi.fastutil.ints.IntSetedgesOf(java.lang.Integer vertex)Returns a set of all edges touching the specified vertex.java.lang.IntegergetEdge(java.lang.Integer sourceVertex, java.lang.Integer targetVertex)Returns an edge connecting source vertex to target vertex if such vertices and such edge exist in this graph.java.lang.IntegergetEdgeSource(java.lang.Integer e)Returns the source vertex of an edge.java.lang.IntegergetEdgeTarget(java.lang.Integer e)Returns the target vertex of an edge.it.unimi.dsi.fastutil.ints.IntSetincomingEdgesOf(java.lang.Integer vertex)Returns a set of all edges incoming into the specified vertex.GraphIterables<java.lang.Integer,java.lang.Integer>iterables()Access the graph using theGraphIterablesinterface.it.unimi.dsi.fastutil.ints.IntSetoutgoingEdgesOf(java.lang.Integer vertex)Returns a set of all edges outgoing from the specified vertex.-
Methods inherited from class org.jgrapht.sux4j.AbstractSuccinctUndirectedGraph
containsEdge, getType, inDegreeOf, outDegreeOf
-
Methods inherited from class org.jgrapht.sux4j.AbstractSuccinctGraph
addEdge, addEdge, addVertex, addVertex, assertVertexExist, containsVertex, getAllEdges, getEdgeSupplier, getEdgeWeight, getVertexSupplier, removeEdge, removeEdge, removeVertex, setEdgeWeight, vertexSet
-
Methods inherited from class org.jgrapht.graph.AbstractGraph
equals, hashCode, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jgrapht.Graph
setEdgeWeight
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
cumulativeOutdegrees
private final it.unimi.dsi.sux4j.util.EliasFanoIndexedMonotoneLongBigList cumulativeOutdegrees
The cumulative list of outdegrees (number of edges in sorted order, including loops).
-
cumulativeIndegrees
private final it.unimi.dsi.sux4j.util.EliasFanoMonotoneLongBigList cumulativeIndegrees
The cumulative list of indegrees (number of edges in reversed order, including loops).
-
successors
private final it.unimi.dsi.sux4j.util.EliasFanoIndexedMonotoneLongBigList successors
The cumulative list of successor (edges in sorted order, including loops) lists.
-
predecessors
private final it.unimi.dsi.sux4j.util.EliasFanoMonotoneLongBigList predecessors
The cumulative list of predecessor (edges in reversed order, including loops) lists.
-
iterables
private final SuccinctIntUndirectedGraph.SuccinctGraphIterables iterables
-
-
Constructor Detail
-
SuccinctIntUndirectedGraph
public SuccinctIntUndirectedGraph(Graph<java.lang.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.
-
SuccinctIntUndirectedGraph
public SuccinctIntUndirectedGraph(int numVertices, java.util.List<Pair<java.lang.Integer,java.lang.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:
SuccinctIntUndirectedGraph(Graph)
-
-
Method Detail
-
containsEdge
public boolean containsEdge(java.lang.Integer 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 interfaceGraph<java.lang.Integer,java.lang.Integer>- Parameters:
e- edge whose presence in this graph is to be tested.- Returns:
trueif this graph contains the specified edge.
-
edgeSet
public java.util.Set<java.lang.Integer> 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.
-
degreeOf
public int degreeOf(java.lang.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".
-
edgesOf
public it.unimi.dsi.fastutil.ints.IntSet edgesOf(java.lang.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.
-
incomingEdgesOf
public it.unimi.dsi.fastutil.ints.IntSet incomingEdgesOf(java.lang.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 interfaceGraph<java.lang.Integer,java.lang.Integer>- 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.
-
outgoingEdgesOf
public it.unimi.dsi.fastutil.ints.IntSet outgoingEdgesOf(java.lang.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 interfaceGraph<java.lang.Integer,java.lang.Integer>- 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.
-
getEdgeSource
public java.lang.Integer getEdgeSource(java.lang.Integer 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 interfaceGraph<java.lang.Integer,java.lang.Integer>- Parameters:
e- edge of interest- Returns:
- source vertex
-
getEdgeTarget
public java.lang.Integer getEdgeTarget(java.lang.Integer 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 interfaceGraph<java.lang.Integer,java.lang.Integer>- Parameters:
e- edge of interest- Returns:
- target vertex
-
getEdge
public java.lang.Integer getEdge(java.lang.Integer sourceVertex, java.lang.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.
-
containsEdge
public boolean containsEdge(java.lang.Integer sourceVertex, java.lang.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 interfaceGraph<java.lang.Integer,java.lang.Integer>- Overrides:
containsEdgein classAbstractGraph<java.lang.Integer,java.lang.Integer>- 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)
-
assertEdgeExist
protected boolean assertEdgeExist(java.lang.Integer e)
Ensures that the specified edge exists in this graph, or else throws exception.- Parameters:
e- edge- Returns:
trueif this assertion holds.- Throws:
java.lang.IllegalArgumentException- if specified edge does not exist in this graph.
-
iterables
public GraphIterables<java.lang.Integer,java.lang.Integer> 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.
-
-