Interface IndexGraph
-
- All Superinterfaces:
Graph
public interface IndexGraph extends Graph
A graph whose vertices and edges identifiers are indices.The
Graphinterface provide addition, removal and querying of vertices and edges, all usingintidentifiers. These identifiers are fixed, and once a vertex or edge is assigned an ID, it will not change during the graph lifetime. On the other hand, an Index graph is aGraphobject in which the vertices and edges identifiers of the graph are always(0,1,2, ...,verticesNum-1)and(0,1,2, ...,edgesNum-1).The index graph invariants allow for a great performance boost, as a simple array or bitmap can be used to associate a value/weight/flag with each vertex/edge. But it does come with a cost: to maintain the invariants, implementations may need to rename existing vertices or edges during the graph lifetime. These renames can be subscribed to using
addVertexSwapListener(IndexSwapListener)andaddEdgeSwapListener(IndexSwapListener).An index graph may be obtained as a view from a regular
GraphusingGraph.indexGraph(), or it can be created by its own usingIndexGraph.Builder. In cases where no removal of vertices or edges is required, and there is no need to use pre-defined IDs, there is no drawback to use theIndexGraphas regularGraph, as it will provide the best performance.All graph algorithms implementations should operation on Index graphs only, for best performance. If a regular
Graphis provided to an algorithm, the Index graph should be retrieved usingGraph.indexGraph(), the algorithm expensive logic should operate on the returned Index graph and finally the result should be transformed back to the regular graph IDs. The mapping from a regular graph IDs to indices and visa versa is exposed usingIndexIdMap, which can be accessed usingGraph.indexGraphVerticesMap()andGraph.indexGraphEdgesMap().- Author:
- Barak Ugav
- See Also:
IndexIdMap
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceIndexGraph.BuilderA builder forIndexGraphobjects.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default voidaddEdge(int source, int target, int edge)Deprecated.voidaddEdgeSwapListener(IndexSwapListener listener)Adds a listener that will be called each time a edge swap is performed.default voidaddVertex(int vertex)Deprecated.voidaddVertexSwapListener(IndexSwapListener listener)Adds a listener that will be called each time a vertex swap is performed.IndexGraphcopy()Create a copy of this graph.it.unimi.dsi.fastutil.ints.IntSetedges()Get the set of all edges of the graph.static IndexGraph.BuildernewBuilderDirected()Create a directed index graph builder.static IndexGraph.BuildernewBuilderUndirected()Create an undirected index graph builder.voidremoveEdge(int edge)Remove an edge from the graph.default voidremoveEdgesOf(int vertex)Remove all the edges of a vertex.voidremoveEdgeSwapListener(IndexSwapListener listener)Removes an edge swap listener.default voidremoveInEdgesOf(int target)Remove all edges whose target istarget.default voidremoveOutEdgesOf(int source)Remove all edges whose source issource.voidremoveVertex(int vertex)Remove a vertex and all its edges from the graph.voidremoveVertexSwapListener(IndexSwapListener listener)Removes a vertex swap listener.default IndexGraphreverseView()Get a reversed view of this graph.default IndexGraphunmodifiableView()Get an unmodifiable view of this graph.it.unimi.dsi.fastutil.ints.IntSetvertices()Get the set of all vertices of the graph.-
Methods inherited from interface com.jgalgo.Graph
addEdge, addEdgesWeights, addEdgesWeights, addVertex, addVerticesWeights, addVerticesWeights, clear, clearEdges, edgeEndpoint, edgeSource, edgeTarget, getCapabilities, getEdge, getEdges, getEdgesWeights, getEdgesWeightsKeys, getVerticesWeights, getVerticesWeightsKeys, indexGraph, indexGraphEdgesMap, indexGraphVerticesMap, inEdges, outEdges, removeEdgesWeights, removeVerticesWeights, reverseEdge
-
-
-
-
Method Detail
-
vertices
it.unimi.dsi.fastutil.ints.IntSet vertices()
Get the set of all vertices of the graph.Each vertex in the graph is identified by a unique non negative integer ID and the returned set is a set of all these identifiers.
The Graph object does not expose an explicit method to get the number of vertices, but it can accessed using this method by
g.vertices().size().In an Index graph, the set of vertices are always
(0,1,2, ...,verticesNum-1).
-
edges
it.unimi.dsi.fastutil.ints.IntSet edges()
Get the set of all edges of the graph.Each edge in the graph is identified by a unique non negative integer ID, and the returned set is a set of all these identifiers.
The Graph object does not expose an explicit method to get the number of edges, but it can accessed using this method by
g.edges().size().In an Index graph, the set of edges are always
(0,1,2, ...,edgesNum-1).
-
addVertex
@Deprecated default void addVertex(int vertex)
Deprecated.Unsupported operation.Index graphs vertices IDs are always
(0,1,2, ...,verticesNum-1)and do not support user chosen IDs.- Specified by:
addVertexin interfaceGraph- Parameters:
vertex- a user chosen identifier for the new vertex- Throws:
UnsupportedOperationException- always
-
removeVertex
void removeVertex(int vertex)
Remove a vertex and all its edges from the graph.After removing a vertex, the graph implementation may swap and rename vertices to maintain its invariants. Theses renames can be subscribed using
addVertexSwapListener(IndexSwapListener).- Specified by:
removeVertexin interfaceGraph- Parameters:
vertex- the vertex identifier to remove
-
addEdge
@Deprecated default void addEdge(int source, int target, int edge)
Deprecated.Unsupported operation.Index graphs edges IDs are always
(0,1,2, ...,edgesNum-1)and do not support user chosen IDs.- Specified by:
addEdgein interfaceGraph- Parameters:
source- a source vertextarget- a target vertexedge- a user chosen identifier for the new edge- Throws:
UnsupportedOperationException- always
-
removeEdge
void removeEdge(int edge)
Remove an edge from the graph.After removing an edge, the graph implementation may swap and rename edges to maintain its invariants. Theses renames can be subscribed using
addEdgeSwapListener(IndexSwapListener).- Specified by:
removeEdgein interfaceGraph- Parameters:
edge- the edge identifier
-
removeEdgesOf
default void removeEdgesOf(int vertex)
Remove all the edges of a vertex.After removing an edge, the graph implementation may swap and rename edges to maintain its invariants. Theses renames can be subscribed using
addEdgeSwapListener(IndexSwapListener).- Specified by:
removeEdgesOfin interfaceGraph- Parameters:
vertex- a vertex in the graph
-
removeOutEdgesOf
default void removeOutEdgesOf(int source)
Remove all edges whose source issource.After removing an edge, the graph implementation may swap and rename edges to maintain its invariants. Theses renames can be subscribed using
addEdgeSwapListener(IndexSwapListener).- Specified by:
removeOutEdgesOfin interfaceGraph- Parameters:
source- a vertex in the graph
-
removeInEdgesOf
default void removeInEdgesOf(int target)
Remove all edges whose target istarget.After removing an edge, the graph implementation may swap and rename edges to maintain its invariants. Theses renames can be subscribed using
addEdgeSwapListener(IndexSwapListener).- Specified by:
removeInEdgesOfin interfaceGraph- Parameters:
target- a vertex in the graph
-
addVertexSwapListener
void addVertexSwapListener(IndexSwapListener listener)
Adds a listener that will be called each time a vertex swap is performed.An
IndexGraphmay rename vertices during its lifetime to maintain the invariant that all vertices are identified by0,1,2,...,verticesNum-1. This method can be used to track these changes, by registering a listener that will be invoked each time such a rename is performed.- Parameters:
listener- a swap listener that will be called each time a vertex swap is performed
-
removeVertexSwapListener
void removeVertexSwapListener(IndexSwapListener listener)
Removes a vertex swap listener.After a listener was added using
addVertexSwapListener(IndexSwapListener), this method removes may remove it.- Parameters:
listener- a swap listener that should be removed
-
addEdgeSwapListener
void addEdgeSwapListener(IndexSwapListener listener)
Adds a listener that will be called each time a edge swap is performed.An
IndexGraphmay rename edges during its lifetime to maintain the invariant that all edges are identified by0,1,2,...,edgesNum-1. This method can be used to track these changes, by registering a listener that will be invoked each time such a rename is performed.- Parameters:
listener- a swap listener that will be called each time a edge swap is performed
-
removeEdgeSwapListener
void removeEdgeSwapListener(IndexSwapListener listener)
Removes an edge swap listener.After a listener was added using
addEdgeSwapListener(IndexSwapListener), this method removes may remove it.- Parameters:
listener- a swap listener that should be removed
-
copy
IndexGraph copy()
Description copied from interface:GraphCreate a copy of this graph.An identical copy of this graph will be created, with the same vertices, edges, weights and capabilities.
-
unmodifiableView
default IndexGraph unmodifiableView()
Description copied from interface:GraphGet an unmodifiable view of this graph.This method return a view of this graph, namely a Graph that contains the same vertices, edges and weights, that is automatically updated when the original graph is updated. The view is unmodifiable, namely all operations that modify the graph will throw
UnsupportedOperationException.- Specified by:
unmodifiableViewin interfaceGraph- Returns:
- an unmodifiable view of this graph
-
reverseView
default IndexGraph reverseView()
Description copied from interface:GraphGet a reversed view of this graph.This method return a view of this graph, namely a Graph that contains the same vertices, edges and weights, that is automatically updated when the original graph is updated and visa versa. The view is reversed, namely each source and target vertices of each edge are swapped.
Note that modifying the returned view will change the original graph.
- Specified by:
reverseViewin interfaceGraph- Returns:
- a reversed view of this graph
-
newBuilderUndirected
static IndexGraph.Builder newBuilderUndirected()
Create an undirected index graph builder.This is the recommended way to instantiate a new undirected index graph.
- Returns:
- a new builder that can build undirected index graphs
-
newBuilderDirected
static IndexGraph.Builder newBuilderDirected()
Create a directed index graph builder.This is the recommended way to instantiate a new directed index graph.
- Returns:
- a new builder that can build directed index graphs
-
-