- All Implemented Interfaces:
- it.unimi.dsi.lang.FlyweightPrototype<ImmutableDirectedGraphAdapter>,- Graph<java.lang.Integer,it.unimi.dsi.fastutil.ints.IntIntPair>
public class ImmutableDirectedGraphAdapter extends AbstractImmutableGraphAdapter<it.unimi.dsi.fastutil.ints.IntIntPair> implements it.unimi.dsi.lang.FlyweightPrototype<ImmutableDirectedGraphAdapter>
ImmutableGraph.
 
 Nodes are instances of Integer corresponding to the index of a node in WebGraph. Edges
 are represented by an IntIntPair. The left and right element are the source and the
 target of the edge. Since the underlying graph is immutable, the resulting graph is unmodifiable.
 Edges are immutable and can be tested for equality (e.g., stored in a dictionary).
 
 WebGraph provides methods for successors only, so to adapt a directed graph you must provide both
 a graph and its transpose (methods to compute the transpose are available in Transform).
 You need to load an ImmutableGraph and its transpose using one of the available load
 methods, and then build an adapter:
 
 immutableGraph = ImmutableGraph.loadMapped("mygraph");
 immutableTranspose = ImmutableGraph.loadMapped("mygraph-t");
 adapter = new ImmutableDirectedGraphAdapter(immutableGraph, immutableTranspose);
 
 
 The first graph will be used to implement outgoingEdgesOf(Integer), and the second graph
 to implement incomingEdgesOf(Integer). It is your responsibility that the two provided
 graphs are one the transpose of the other (for each arc
 x → y in a graph there must be an arc
 y → x in the other, and vice versa). No check will be
 performed. Note that computing the number of edges of a
 graph requires a full scan of the edge set if ImmutableGraph.numArcs() is not supported
 (the first time—then it will be cached).
 
 If you use a load method that does not provide random access, most methods will throw an
 UnsupportedOperationException.
 
 If you know that you will never used methods based on incoming edges
 (incomingEdgesOf(Integer), inDegreeOf(Integer), edgesOf(Integer),
 degreeOf(Integer)), you can also use the constructor using just a graph, but all such
 methods will throw a NullPointerException:
 
 immutableGraph = ImmutableGraph.loadMapped("mygraph");
 adapter = new ImmutableDirectedGraphAdapter(immutableGraph);
 
 
 If necessary, you can adapt a big WebGraph
 graph with at most Integer.MAX_VALUE vertices using the suitable
 wrapper.
 
Thread safety
 This class is not thread safe: following the FlyweightPrototype pattern, users can access
 concurrently the graph by getting lightweight copies.
 
Fast adjacency check
 As it happens for the sparse representation of JGraphT, usually a WebGraph compressed
 representation requires scanning the adjacency list of a node to
 test whether a specific arc exists. However, if you adapt
 a WebGraph class (such as EFGraph) which provides skippable iterators with fast skipping, adjacency can be tested more quickly (e.g., essentially
 in constant time in the case of EFGraph).
- Author:
- Sebastiano Vigna
- See Also:
- AbstractImmutableBigGraphAdapter
- 
Field Summary
- 
Constructor SummaryConstructors Constructor Description ImmutableDirectedGraphAdapter(it.unimi.dsi.webgraph.ImmutableGraph immutableGraph)Creates an adapter for a directed immutable graph implementing only methods based on outgoing edges.ImmutableDirectedGraphAdapter(it.unimi.dsi.webgraph.ImmutableGraph immutableGraph, it.unimi.dsi.webgraph.ImmutableGraph immutableTranspose)Creates an adapter for a directed immutable graph.
- 
Method SummaryModifier and Type Method Description booleancontainsEdge(it.unimi.dsi.fastutil.ints.IntIntPair e)Returnstrueif this graph contains the specified edge.ImmutableDirectedGraphAdaptercopy()intdegreeOf(java.lang.Integer vertex)Returns the degree of the specified vertex.java.util.Set<it.unimi.dsi.fastutil.ints.IntIntPair>edgeSet()Returns a set of the edges contained in this graph.java.util.Set<it.unimi.dsi.fastutil.ints.IntIntPair>edgesOf(java.lang.Integer vertex)Returns a set of all edges touching the specified vertex.GraphTypegetType()Get the graph type.java.util.Set<it.unimi.dsi.fastutil.ints.IntIntPair>incomingEdgesOf(java.lang.Integer vertex)Returns a set of all edges incoming into the specified vertex.intinDegreeOf(java.lang.Integer vertex)Returns the "in degree" of the specified vertex.GraphIterables<java.lang.Integer,it.unimi.dsi.fastutil.ints.IntIntPair>iterables()Access the graph using theGraphIterablesinterface.protected it.unimi.dsi.fastutil.ints.IntIntPairmakeEdge(int x, int y)intoutDegreeOf(java.lang.Integer vertex)Returns the "out degree" of the specified vertex.java.util.Set<it.unimi.dsi.fastutil.ints.IntIntPair>outgoingEdgesOf(java.lang.Integer vertex)Returns a set of all edges outgoing from the specified vertex.Methods inherited from class org.jgrapht.webgraph.AbstractImmutableGraphAdapteraddEdge, addEdge, addVertex, addVertex, containsEdge, containsEdgeFast, containsVertex, getAllEdges, getEdge, getEdgeSource, getEdgeSupplier, getEdgeTarget, getEdgeWeight, getVertexSupplier, removeEdge, removeEdge, removeVertex, setEdgeWeight, vertexSetMethods inherited from class org.jgrapht.graph.AbstractGraphassertVertexExist, equals, hashCode, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
- 
Constructor Details- 
ImmutableDirectedGraphAdapterpublic ImmutableDirectedGraphAdapter(it.unimi.dsi.webgraph.ImmutableGraph immutableGraph, it.unimi.dsi.webgraph.ImmutableGraph immutableTranspose)Creates an adapter for a directed immutable graph.It is responsibility of the caller that the two provided graphs are one the transpose of the other (for each arc x → y in a graph there must be an arc y → x in the other). If this property is not true, results will be unpredictable. - Parameters:
- immutableGraph- an immutable graph.
- immutableTranspose- its transpose.
 
- 
ImmutableDirectedGraphAdapterpublic ImmutableDirectedGraphAdapter(it.unimi.dsi.webgraph.ImmutableGraph immutableGraph)Creates an adapter for a directed immutable graph implementing only methods based on outgoing edges.- Parameters:
- immutableGraph- an immutable graph.
 
 
- 
- 
Method Details- 
makeEdgeprotected it.unimi.dsi.fastutil.ints.IntIntPair makeEdge(int x, int y)- Specified by:
- makeEdgein class- AbstractImmutableGraphAdapter<it.unimi.dsi.fastutil.ints.IntIntPair>
 
- 
containsEdgepublic boolean containsEdge(it.unimi.dsi.fastutil.ints.IntIntPair 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<java.lang.Integer,it.unimi.dsi.fastutil.ints.IntIntPair>
- Parameters:
- e- edge whose presence in this graph is to be tested.
- Returns:
- trueif this graph contains the specified edge.
 
- 
edgeSetpublic java.util.Set<it.unimi.dsi.fastutil.ints.IntIntPair> 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(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". 
- 
edgesOfpublic java.util.Set<it.unimi.dsi.fastutil.ints.IntIntPair> 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.
- 
inDegreeOfpublic int inDegreeOf(java.lang.Integer vertex)Description copied from interface:GraphReturns the "in degree" of the specified vertex.The "in degree" of a vertex in a directed graph is the number of inward directed edges from that vertex. See http://mathworld.wolfram.com/Indegree.html. In the case of undirected graphs this method returns the number of edges touching the vertex. Edges with same source and target vertices (self-loops) are counted twice. - Specified by:
- inDegreeOfin interface- Graph<java.lang.Integer,it.unimi.dsi.fastutil.ints.IntIntPair>
- Parameters:
- vertex- vertex whose degree is to be calculated.
- Returns:
- the degree of the specified vertex.
 
- 
incomingEdgesOfpublic java.util.Set<it.unimi.dsi.fastutil.ints.IntIntPair> 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 interface- Graph<java.lang.Integer,it.unimi.dsi.fastutil.ints.IntIntPair>
- 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.
 
- 
outDegreeOfpublic int outDegreeOf(java.lang.Integer vertex)Description copied from interface:GraphReturns the "out degree" of the specified vertex.The "out degree" of a vertex in a directed graph is the number of outward directed edges from that vertex. See http://mathworld.wolfram.com/Outdegree.html. In the case of undirected graphs this method returns the number of edges touching the vertex. Edges with same source and target vertices (self-loops) are counted twice. - Specified by:
- outDegreeOfin interface- Graph<java.lang.Integer,it.unimi.dsi.fastutil.ints.IntIntPair>
- Parameters:
- vertex- vertex whose degree is to be calculated.
- Returns:
- the degree of the specified vertex.
 
- 
outgoingEdgesOfpublic java.util.Set<it.unimi.dsi.fastutil.ints.IntIntPair> 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 interface- Graph<java.lang.Integer,it.unimi.dsi.fastutil.ints.IntIntPair>
- 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.
 
- 
getTypeDescription copied from interface:GraphGet the graph type. The graph type can be used to query for additional metadata such as whether the graph supports directed or undirected edges, self-loops, multiple (parallel) edges, weights, etc.
- 
copy- Specified by:
- copyin interface- it.unimi.dsi.lang.FlyweightPrototype<ImmutableDirectedGraphAdapter>
 
- 
iterablesDescription 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.
 
-