Interface IndexGraph
-
- All Known Implementing Classes:
GraphBaseWithEdgeEndpointsContainer
public interface IndexGraph extends IntGraph
A graph whose vertices and edges identifiers are indices.The
Graphinterface provide addition, removal and querying of vertices and edges, all using some hashable identifiers. 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 aIntGraphobject 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
addVertexRemoveListener(IndexRemoveListener)andaddEdgeRemoveListener(IndexRemoveListener).An index graph may be obtained as a view from a regular
GraphusingGraph.indexGraph(), or it can be created on its own usingIndexGraphFactory. 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 of using theIndexGraphas a regularIntGraph, as it will expose an identical functionality while providing better performance.If an
IndexGraphis obtained from a regularGraph(orIntGraph) usingGraph.indexGraph(), theIndexGraphshould not be modified directly. Vertices/edges/weights should be added/removed only via the original fixed identifiers graph.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 vice versa is provided byIndexIdMap, which can be accessed usingGraph.indexGraphVerticesMap()andGraph.indexGraphEdgesMap().To create a new empty index graph, use
newUndirected()ornewDirected(). The returned graph will use the default implementation. For more control over the graph details, seeIndexGraphFactory. To construct an immutable index graph, useIndexGraphBuilder.- Author:
- Barak Ugav
- See Also:
IndexIdMap
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description intaddEdge(int source, int target)Add a new edge to the graph.default voidaddEdge(int source, int target, int edge)Deprecated.voidaddEdgeRemoveListener(IndexRemoveListener listener)Adds a listener that will be called each time a edge swap is performed.default <T,WeightsT extends Weights<Integer,T>>
WeightsTaddEdgesWeights(String key, Class<? super T> type)Add a new weights container associated with the edges of this graph.<T,WeightsT extends Weights<Integer,T>>
WeightsTaddEdgesWeights(String key, Class<? super T> type, T defVal)Add a new weights container associated with the edges of this graph with default value.intaddVertex()Add a new vertex to the graph.default voidaddVertex(int vertex)Deprecated.voidaddVertexRemoveListener(IndexRemoveListener listener)Adds a listener that will be called each time a vertex remove or swap is performed.default <T,WeightsT extends Weights<Integer,T>>
WeightsTaddVerticesWeights(String key, Class<? super T> type)Add a new weights container associated with the vertices of this graph.<T,WeightsT extends Weights<Integer,T>>
WeightsTaddVerticesWeights(String key, Class<? super T> type, T defVal)Add a new weights container associated with the vertices of this graph with default value.voidclear()Clear the graph completely by removing all vertices and edges.voidclearEdges()Remove all the edges from the graph.default IndexGraphcopy()Create a copy of this graph, with the same vertices and edges, without copying weights.default IndexGraphcopy(boolean copyWeights)Create a copy of this graph, with the same vertices and edges, with/without copying weights.IntSetedges()Get the set of all edges of the graph.default IndexGraphimmutableCopy()Create an immutable copy of this graph, with the same vertices and edges, without copying weights.default IndexGraphimmutableCopy(boolean copyWeights)Create an immutable copy of this graph, with the same vertices and edges, with/without copying weights.default IndexGraphimmutableView()Get an immutable view of this graph.default IndexGraphindexGraph()Deprecated.this function will always return the same graph, no reason to call itdefault IndexIntIdMapindexGraphEdgesMap()Deprecated.this function will always return the identity mapping, no reason to call itdefault IndexIntIdMapindexGraphVerticesMap()Deprecated.this function will always return the identity mapping, no reason to call itstatic IndexGraphnewDirected()Create a new directed empty index graph.static IndexGraphnewUndirected()Create a new undirected empty index graph.voidremoveEdge(int edge)Remove an edge from the graph.voidremoveEdgeRemoveListener(IndexRemoveListener listener)Removes an edge remove listener.default voidremoveEdgesOf(int vertex)Remove all the edges of a vertex.voidremoveEdgesWeights(String key)Remove a weight type associated with the edges of the graph.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.voidremoveVertexRemoveListener(IndexRemoveListener listener)Removes a vertex remove listener.voidremoveVerticesWeights(String key)Remove a weight type associated with the vertices of the graph.voidreverseEdge(int edge)Reverse an edge by switching its source and target.default IndexGraphreverseView()Get a reversed view of this graph.default IndexGraphundirectedView()Get an undirected view of this (directed) graph.IntSetvertices()Get the set of all vertices of the graph.-
Methods inherited from interface com.jgalgo.graph.Graph
getEdgesWeightsKeys, getVerticesWeightsKeys, isAllowParallelEdges, isAllowSelfEdges, isDirected
-
Methods inherited from interface com.jgalgo.graph.IntGraph
addEdge, addVertex, edgeEndpoint, edgeEndpoint, edgeSource, edgeSource, edgeTarget, edgeTarget, getEdge, getEdge, getEdges, getEdges, getEdgesIWeights, getEdgesWeights, getVerticesIWeights, getVerticesWeights, inEdges, inEdges, outEdges, outEdges, removeEdge, removeEdgesOf, removeInEdgesOf, removeOutEdgesOf, removeVertex, reverseEdge, subGraphCopy
-
-
-
-
Method Detail
-
vertices
IntSet vertices()
Get the set of all vertices of the graph.Each vertex in the graph is identified by a unique non null hashable object 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
IntSet edges()
Get the set of all edges of the graph.Each edge in the graph is identified by a unique non null hashable object, 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
int addVertex()
Add a new vertex to the graph.The graph implementation will choose a new
intidentifier which is not currently used as one of the graph edges, and will return it as the new vertex ID.If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.
-
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 interfaceIntGraph- 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
addVertexRemoveListener(IndexRemoveListener).If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.- Specified by:
removeVertexin interfaceIntGraph- Parameters:
vertex- the vertex identifier to remove
-
addEdge
int addEdge(int source, int target)Add a new edge to the graph.The graph implementation will choose a new
intidentifier which is not currently used as one of the graph edges, and will return it as the new edge ID.If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.
-
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 interfaceIntGraph- 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
addEdgeRemoveListener(IndexRemoveListener).If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.- Specified by:
removeEdgein interfaceIntGraph- 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
addEdgeRemoveListener(IndexRemoveListener).If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.- Specified by:
removeEdgesOfin interfaceIntGraph- 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
addEdgeRemoveListener(IndexRemoveListener).If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.- Specified by:
removeOutEdgesOfin interfaceIntGraph- 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
addEdgeRemoveListener(IndexRemoveListener).If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.- Specified by:
removeInEdgesOfin interfaceIntGraph- Parameters:
target- a vertex in the graph
-
reverseEdge
void reverseEdge(int edge)
Reverse an edge by switching its source and target.If the graph is undirected, this method does nothing.
If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.- Specified by:
reverseEdgein interfaceIntGraph- Parameters:
edge- an existing edge in the graph
-
clear
void clear()
Clear the graph completely by removing all vertices and edges.This function might be used to reuse an already allocated graph object.
Note that this function also clears any weights associated with the vertices or edges.
If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.
-
clearEdges
void clearEdges()
Remove all the edges from the graph.Note that this function also clears any weights associated with the edges.
If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.- Specified by:
clearEdgesin interfaceGraph<Integer,Integer>
-
addVerticesWeights
default <T,WeightsT extends Weights<Integer,T>> WeightsT addVerticesWeights(String key, Class<? super T> type)
Add a new weights container associated with the vertices of this graph.The created weights will be bounded to this graph, and will be updated when the graph is updated (when vertices are added or removed). To create an external weights container, for example in cases the graph is a user input and we are not allowed to modify it, use
Weights.createExternalVerticesWeights(Graph, Class).Graph<String, Int> g = ...; g.newVertex("Alice"); g.newVertex("Bob"); Weights<String> names = g.addVerticesWeights("surname", String.class); names.set("Alice", "Miller"); names.set("Bob", "Jones"); WeightsInt ages = g.addVerticesWeights("age", int.class); ages.set("Alice", 42); ages.set("Bob", 35);See
Weightsfor a complete documentation of the weights containers.If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.- Specified by:
addVerticesWeightsin interfaceGraph<Integer,Integer>- Type Parameters:
T- The weight data typeWeightsT- the weights container, used to avoid casts of containers of primitive types such asWeightsInt,WeightsDoubleect.- Parameters:
key- key of the weightstype- the type of the weights, used for primitive types weights- Returns:
- a new weights container
-
addVerticesWeights
<T,WeightsT extends Weights<Integer,T>> WeightsT addVerticesWeights(String key, Class<? super T> type, T defVal)
Add a new weights container associated with the vertices of this graph with default value.The created weights will be bounded to this graph, and will be updated when the graph is updated. To create an external weights container, for example in cases the graph is a user input we are not allowed to modify it, use
Weights.createExternalVerticesWeights(Graph, Class, Object).Graph<String, Int> g = ...; g.newVertex("Alice"); g.newVertex("Bob"); g.newVertex("Charlie"); Weights<String> names = g.addVerticesWeights("name", String.class, "Unknown"); names.set("Alice", "Miller"); names.set("Bob", "Jones"); assert "Miller".equals(names.get("Alice")) assert "Jones".equals(names.get("Bob")) assert "Unknown".equals(names.get("Charlie"))See
Weightsfor a complete documentation of the weights containers.If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.- Specified by:
addVerticesWeightsin interfaceGraph<Integer,Integer>- Type Parameters:
T- The weight data typeWeightsT- the weights container, used to avoid casts of containers of primitive types such asWeightsInt,WeightsDoubleect.- Parameters:
key- key of the weightstype- the type of the weights, used for primitive types weightsdefVal- default value use for the weights container- Returns:
- a new weights container
-
removeVerticesWeights
void removeVerticesWeights(String key)
Remove a weight type associated with the vertices of the graph.See
Weightsfor a complete documentation of the weights containers.If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.- Specified by:
removeVerticesWeightsin interfaceGraph<Integer,Integer>- Parameters:
key- the key of the weights
-
addEdgesWeights
default <T,WeightsT extends Weights<Integer,T>> WeightsT addEdgesWeights(String key, Class<? super T> type)
Add a new weights container associated with the edges of this graph.The created weights will be bounded to this graph, and will be updated when the graph is updated. To create an external weights container, for example in cases the graph is a user input you are not allowed to modify it, use
Weights.createExternalEdgesWeights(Graph, Class).Graph<String, Integer> g = ...; g.addVertex("Berlin"); g.addVertex("Leipzig"); g.addVertex("Dresden"); g.addEdge("Berlin", "Leipzig", 9); g.addEdge("Berlin", "Dresden", 13); Weights<String> roadTypes = g.addEdgesWeights("roadType", String.class); roadTypes.set(9, "Asphalt"); roadTypes.set(13, "Gravel"); WeightsDouble roadLengths = g.addEdgesWeights("roadLength", double.class); roadLengths.set(9, 42); roadLengths.set(13, 35);See
Weightsfor a complete documentation of the weights containers.If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.- Specified by:
addEdgesWeightsin interfaceGraph<Integer,Integer>- Type Parameters:
T- The weight data typeWeightsT- the weights container, used to avoid casts of containers of primitive types such asWeightsInt,WeightsDoubleect.- Parameters:
key- key of the weightstype- the type of the weights, used for primitive types weights- Returns:
- a new weights container
-
addEdgesWeights
<T,WeightsT extends Weights<Integer,T>> WeightsT addEdgesWeights(String key, Class<? super T> type, T defVal)
Add a new weights container associated with the edges of this graph with default value.The created weights will be bounded to this graph, and will be updated when the graph is updated. To create an external weights container, for example in cases the graph is a user input we are not allowed to modify it, use
Weights.createExternalEdgesWeights(Graph, Class, Object).Graph<String, Integer> g = ...; g.addVertex("Berlin"); g.addVertex("Leipzig"); g.addVertex("Dresden"); g.addEdge("Berlin", "Leipzig", 9); g.addEdge("Berlin", "Dresden", 13); g.addEdge("Dresden", "Leipzig", 14); Weights<String> roadTypes = g.addEdgesWeights("roadType", String.class, "Unknown"); roadTypes.set(9, "Asphalt"); roadTypes.set(13, "Gravel"); assert "Asphalt".equals(names.get(9)) assert "Gravel".equals(names.get(13)) assert "Unknown".equals(names.get(14))See
Weightsfor a complete documentation of the weights containers.If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.- Specified by:
addEdgesWeightsin interfaceGraph<Integer,Integer>- Type Parameters:
T- The weight data typeWeightsT- the weights container, used to avoid casts of containers of primitive types such asWeightsInt,WeightsDoubleect.- Parameters:
key- key of the weightstype- the type of the weights, used for primitive types weightsdefVal- default value use for the weights container- Returns:
- a new weights container
-
removeEdgesWeights
void removeEdgesWeights(String key)
Remove a weight type associated with the edges of the graph.See
Weightsfor a complete documentation of the weights containers.If this index graph object was obtained from a regular
GraphusingGraph.indexGraph(), this method should not be called. Use the original graph instead.- Specified by:
removeEdgesWeightsin interfaceGraph<Integer,Integer>- Parameters:
key- the key of the weights
-
addVertexRemoveListener
void addVertexRemoveListener(IndexRemoveListener listener)
Adds a listener that will be called each time a vertex remove or 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.If a vertex is removed with the last index (
verticesNum-1), the vertex can simply be removed. Otherwise, the vertex will be swapped with the last vertex and then removed. In both cases, the listener will be called.- Parameters:
listener- a remove listener that will be called each time a vertex remove or swap is performed
-
removeVertexRemoveListener
void removeVertexRemoveListener(IndexRemoveListener listener)
Removes a vertex remove listener.After a listener was added using
addVertexRemoveListener(IndexRemoveListener), this method can remove it.- Parameters:
listener- a remove listener that should be removed
-
addEdgeRemoveListener
void addEdgeRemoveListener(IndexRemoveListener 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.If an edge is removed with the last index (
edgesNum-1), the edge can simply be removed. Otherwise, the edge will be swapped with the last edge and then removed. In both cases, the listener will be called.- Parameters:
listener- a remove listener that will be called each time a edge remove or swap is performed
-
removeEdgeRemoveListener
void removeEdgeRemoveListener(IndexRemoveListener listener)
Removes an edge remove listener.After a listener was added using
addEdgeRemoveListener(IndexRemoveListener), this method can remove it.- Parameters:
listener- a remove listener that should be removed
-
indexGraph
@Deprecated default IndexGraph indexGraph()
Deprecated.this function will always return the same graph, no reason to call itThe index graph of anIndexGraphis itself.- Specified by:
indexGraphin interfaceGraph<Integer,Integer>- Returns:
- this graph
-
indexGraphVerticesMap
@Deprecated default IndexIntIdMap indexGraphVerticesMap()
Deprecated.this function will always return the identity mapping, no reason to call itThe IDs and indices of anIndexGraphare the same.- Specified by:
indexGraphVerticesMapin interfaceGraph<Integer,Integer>- Specified by:
indexGraphVerticesMapin interfaceIntGraph- Returns:
- a mapping that map vertices IDs to vertices indices
-
indexGraphEdgesMap
@Deprecated default IndexIntIdMap indexGraphEdgesMap()
Deprecated.this function will always return the identity mapping, no reason to call itThe IDs and indices of anIndexGraphare the same.- Specified by:
indexGraphEdgesMapin interfaceGraph<Integer,Integer>- Specified by:
indexGraphEdgesMapin interfaceIntGraph- Returns:
- a mapping that map edges IDs to edges indices
-
copy
default IndexGraph copy()
Description copied from interface:GraphCreate a copy of this graph, with the same vertices and edges, without copying weights.An identical copy of this graph will be created, with the same vertices, edges, capabilities (inclusive) such as self edges and parallel edges support, without copying the vertices/edges weights. The returned graph will always be modifiable, with no side affects on the original graph.
-
copy
default IndexGraph copy(boolean copyWeights)
Description copied from interface:GraphCreate a copy of this graph, with the same vertices and edges, with/without copying weights.An identical copy of this graph will be created, with the same vertices, edges, capabilities (inclusive) such as self edges and parallel edges support, with/without copying the vertices/edges weights. The returned graph will always be modifiable, with no side affects on the original graph.
Note that although
g.equals(g.copy())is alwaystrueifcopyWeightsistrue, there is no guarantee thatg.indexGraph().equals(g.copy().indexGraph()). Namely, when the graph is copied, new indices may be assigned to the vertices and edges.- Specified by:
copyin interfaceGraph<Integer,Integer>- Specified by:
copyin interfaceIntGraph- Parameters:
copyWeights- iftrue, the weights of the vertices and edges will be copied to the new graph- Returns:
- an identical copy of the given graph, with the same vertices and edges, with/without this graph weights
-
immutableCopy
default IndexGraph immutableCopy()
Description copied from interface:GraphCreate an immutable copy of this graph, with the same vertices and edges, without copying weights.An identical copy of this graph will be created, with the same vertices and edges, without copying the vertices/edges weights. The returned graph will be immutable, and no vertices/edges/weights can be added or removed from it.
A more compact and efficient representation may be used for the graph, if its known that it will not be changed in the future. It may be more efficient to create an immutable copy of a graph and pass the copy to algorithms instead of using the original graph.
Note that although
g.equals(g.immutableCopy())is alwaystrue, there is no guarantee thatg.indexGraph().equals(g.immutableCopy().indexGraph()). Namely, when the graph is copied, new indices may be assigned to the vertices and edges.- Specified by:
immutableCopyin interfaceGraph<Integer,Integer>- Specified by:
immutableCopyin interfaceIntGraph- Returns:
- an immutable copy of this graph, with the same vertices and edges, without this graph weights
-
immutableCopy
default IndexGraph immutableCopy(boolean copyWeights)
Description copied from interface:GraphCreate an immutable copy of this graph, with the same vertices and edges, with/without copying weights.An identical copy of this graph will be created, with the same vertices and edges, with/without copying the vertices/edges weights. The returned graph will be immutable, and no vertices/edges/weights can be added or removed from it.
A more compact and efficient representation may be used for the graph, if its known that it will not be changed in the future. It may be more efficient to create an immutable copy of a graph and pass the copy to algorithms instead of using the original graph.
Note that although
g.equals(g.immutableCopy())is alwaystrueifcopyWeightsistrue, there is no guarantee thatg.indexGraph().equals(g.immutableCopy().indexGraph()). Namely, when the graph is copied, new indices may be assigned to the vertices and edges.- Specified by:
immutableCopyin interfaceGraph<Integer,Integer>- Specified by:
immutableCopyin interfaceIntGraph- Parameters:
copyWeights- iftrue, the weights of the vertices and edges will be copied to the new graph- Returns:
- an immutable copy of this graph, with the same vertices and edges, with/without this graph weights
-
immutableView
default IndexGraph immutableView()
Description copied from interface:GraphGet an immutable 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 immutable, namely all operations that modify the graph will throw
UnsupportedOperationException.- Specified by:
immutableViewin interfaceGraph<Integer,Integer>- Specified by:
immutableViewin interfaceIntGraph- Returns:
- an immutable 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 vice 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<Integer,Integer>- Specified by:
reverseViewin interfaceIntGraph- Returns:
- a reversed view of this graph
-
undirectedView
default IndexGraph undirectedView()
Description copied from interface:GraphGet an undirected view of this (directed) 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 vice versa. The view is undirected, namely each directed edge \((u,v)\) will exist in all the sets
g.outEdges(u),g.inEdges(u),g.outEdges(v)andg.inEdges(u). The view will contain the same number of edges as this graph.The returned view will return
trueforGraph.isAllowParallelEdges()even if the original graph does not support parallel edges. This is because the original graph could have both \((u,v)\) in \((v,u)\) without violating the parallel edges constraint, but the view will treat them as parallel edges as the direction is 'forgotten'.If this graph is undirected, this function return the graph itself.
- Specified by:
undirectedViewin interfaceGraph<Integer,Integer>- Specified by:
undirectedViewin interfaceIntGraph- Returns:
- an undirected view of this graph
-
newUndirected
static IndexGraph newUndirected()
Create a new undirected empty index graph.The returned graph will be implemented using the default implementation. For more control over the graph details, see
IndexGraphFactory.- Returns:
- a new undirected empty index graph
-
newDirected
static IndexGraph newDirected()
Create a new directed empty index graph.The returned graph will be implemented using the default implementation. For more control over the graph details, see
IndexGraphFactory.- Returns:
- a new directed empty index graph
-
-