Class GraphBaseWithEdgeEndpointsContainer
- java.lang.Object
-
- com.jgalgo.graph.GraphBaseWithEdgeEndpointsContainer
-
-
Method Summary
All Methods Instance Methods Concrete Methods Default Methods Modifier and Type Method Description int
addEdge(int source, int target)
Add a new edge to the graph.void
addEdgeRemoveListener(IndexRemoveListener listener)
Adds a listener that will be called each time a edge swap is performed.<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.int
addVertex()
Add a new vertex to the graph.void
addVertexRemoveListener(IndexRemoveListener listener)
Adds a listener that will be called each time a vertex remove or swap is performed.<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.void
clear()
Clear the graph completely by removing all vertices and edges.void
clearEdges()
Remove all the edges from the graph.default int
edgeEndpoint(int edge, int endpoint)
Get the other end-point of an edge.long[]
edgeEndpoints()
com.jgalgo.graph.GraphElementSet
edges()
Get the set of all edges of the graph.default int
edgeSource(int edge)
Get the source vertex of an edge.default int
edgeTarget(int edge)
Get the target vertex of an edge.boolean
equals(Object other)
IEdgeSet
getEdges(int source, int target)
Get the edges whose source issource
and target istarget
.<T,WeightsT extends IWeights<T>>
WeightsTgetEdgesIWeights(String key)
Get the edges weights of some key.Set<String>
getEdgesWeightsKeys()
Get the keys of all the associated edges weights.<T,WeightsT extends IWeights<T>>
WeightsTgetVerticesIWeights(String key)
Get the vertices weights of some key.Set<String>
getVerticesWeightsKeys()
Get the keys of all the associated vertices weights.int
hashCode()
boolean
isAllowParallelEdges()
Checks whether parallel edges are supported.boolean
isAllowSelfEdges()
Checks whether self edges are supported.boolean
isDirected()
Checks whether the graph is directed.void
removeEdge(int edge)
Remove an edge from the graph.void
removeEdgeRemoveListener(IndexRemoveListener listener)
Removes an edge remove listener.void
removeEdgesWeights(String key)
Remove a weight type associated with the edges of the graph.void
removeVertex(int vertex)
Remove a vertex and all its edges from the graph.void
removeVertexRemoveListener(IndexRemoveListener listener)
Removes a vertex remove listener.void
removeVerticesWeights(String key)
Remove a weight type associated with the vertices of the graph.default void
replaceEdgeEndpoint(int edge, int oldEndpoint, int newEndpoint)
default void
replaceEdgeSource(int edge, int newSource)
default void
replaceEdgeTarget(int edge, int newTarget)
default void
setEndpoints(int edge, int source, int target)
String
toString()
com.jgalgo.graph.GraphElementSet
vertices()
Get the set of all vertices of the graph.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.jgalgo.graph.Graph
getEdgesWeightsKeys, getVerticesWeightsKeys, isAllowParallelEdges, isAllowSelfEdges, isDirected
-
Methods inherited from interface com.jgalgo.graph.IndexGraph
addEdge, addEdgeRemoveListener, addEdgesWeights, addEdgesWeights, addVertex, addVertex, addVertexRemoveListener, addVerticesWeights, addVerticesWeights, clear, copy, copy, edges, immutableCopy, immutableCopy, immutableView, indexGraph, indexGraphEdgesMap, indexGraphVerticesMap, removeEdge, removeEdgeRemoveListener, removeEdgesOf, removeEdgesWeights, removeInEdgesOf, removeOutEdgesOf, removeVertex, removeVertexRemoveListener, removeVerticesWeights, reverseEdge, reverseView, undirectedView, vertices
-
Methods inherited from interface com.jgalgo.graph.IntGraph
addEdge, addVertex, edgeEndpoint, edgeSource, edgeTarget, getEdge, getEdge, getEdges, getEdges, getEdgesIWeights, getEdgesWeights, getVerticesIWeights, getVerticesWeights, inEdges, inEdges, outEdges, outEdges, removeEdge, removeEdgesOf, removeInEdgesOf, removeOutEdgesOf, removeVertex, reverseEdge, subGraphCopy
-
-
-
-
Method Detail
-
addEdge
public int addEdge(int source, int target)
Description copied from interface:IndexGraph
Add a new edge to the graph.The graph implementation will choose a new
int
identifier 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
Graph
usingGraph.indexGraph()
, this method should not be called. Use the original graph instead.- Specified by:
addEdge
in interfaceIndexGraph
- Specified by:
addEdge
in interfaceIntGraph
- Parameters:
source
- a source vertextarget
- a target vertex- Returns:
- the new edge identifier
-
clearEdges
public void clearEdges()
Description copied from interface:IndexGraph
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
Graph
usingGraph.indexGraph()
, this method should not be called. Use the original graph instead.- Specified by:
clearEdges
in interfaceGraph<Integer,Integer>
- Specified by:
clearEdges
in interfaceIndexGraph
-
edgeEndpoints
public long[] edgeEndpoints()
-
setEndpoints
public default void setEndpoints(int edge, int source, int target)
-
edgeEndpoint
public default int edgeEndpoint(int edge, int endpoint)
Description copied from interface:IntGraph
Get the other end-point of an edge.Given an edge \((u,v)\) and a vertex \(w\), assuming \(w\) is an endpoint of the edge, namely that \(w\) is either \(u\) or \(v\), the method will return the other endpoint which is not \(w\). If \(w=u\) the method will return \(v\), if \(w=v\) the method will return \(u\).
- Specified by:
edgeEndpoint
in interfaceIntGraph
- Parameters:
edge
- an edge identifierendpoint
- one of the edge end-point- Returns:
- the other end-point of the edge
-
edgeSource
public default int edgeSource(int edge)
Description copied from interface:IntGraph
Get the source vertex of an edge.If the graph is undirected, this function return an arbitrary end-point of the edge, but always other end-point than
IntGraph.edgeTarget(int)
returns.- Specified by:
edgeSource
in interfaceIntGraph
- Parameters:
edge
- the edge identifier- Returns:
- the edge source vertex
-
edgeTarget
public default int edgeTarget(int edge)
Description copied from interface:IntGraph
Get the target vertex of an edge.If the graph is undirected, this function return an arbitrary end-point of the edge, but always the other end-point than
IntGraph.edgeSource(int)
returns.- Specified by:
edgeTarget
in interfaceIntGraph
- Parameters:
edge
- the edge identifier- Returns:
- the edge target vertex
-
replaceEdgeSource
public default void replaceEdgeSource(int edge, int newSource)
-
replaceEdgeTarget
public default void replaceEdgeTarget(int edge, int newTarget)
-
replaceEdgeEndpoint
public default void replaceEdgeEndpoint(int edge, int oldEndpoint, int newEndpoint)
-
vertices
public final com.jgalgo.graph.GraphElementSet vertices()
Description copied from interface:IndexGraph
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)
.- Returns:
- a set containing all vertices of the graph
-
edges
public final com.jgalgo.graph.GraphElementSet edges()
Description copied from interface:IndexGraph
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)
.- Returns:
- a set containing all edges of the graph
-
addVertex
public int addVertex()
Description copied from interface:IndexGraph
Add a new vertex to the graph.The graph implementation will choose a new
int
identifier 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
Graph
usingGraph.indexGraph()
, this method should not be called. Use the original graph instead.- Returns:
- the new vertex identifier
-
removeVertex
public final void removeVertex(int vertex)
Description copied from interface:IndexGraph
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
IndexGraph.addVertexRemoveListener(IndexRemoveListener)
.If this index graph object was obtained from a regular
Graph
usingGraph.indexGraph()
, this method should not be called. Use the original graph instead.- Parameters:
vertex
- the vertex identifier to remove
-
removeEdge
public final void removeEdge(int edge)
Description copied from interface:IndexGraph
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
IndexGraph.addEdgeRemoveListener(IndexRemoveListener)
.If this index graph object was obtained from a regular
Graph
usingGraph.indexGraph()
, this method should not be called. Use the original graph instead.- Parameters:
edge
- the edge identifier
-
clear
public void clear()
Description copied from interface:IndexGraph
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
Graph
usingGraph.indexGraph()
, this method should not be called. Use the original graph instead.
-
getVerticesIWeights
public <T,WeightsT extends IWeights<T>> WeightsT getVerticesIWeights(String key)
Description copied from interface:IntGraph
Get the vertices weights of some key.See
IWeights
for a complete documentation of the weights containers.- Type Parameters:
T
- The weight data typeWeightsT
- the weights container, used to avoid casts of containers of primitive types such asIWeightsInt
,IWeightsDouble
ect.- Parameters:
key
- key of the weights- Returns:
- vertices weights of the key, or
null
if no container found with the specified key
-
getVerticesWeightsKeys
public Set<String> getVerticesWeightsKeys()
Description copied from interface:Graph
Get the keys of all the associated vertices weights.See
Weights
for a complete documentation of the weights containers.- Returns:
- the keys of all the associated vertices weights
-
removeVerticesWeights
public void removeVerticesWeights(String key)
Description copied from interface:IndexGraph
Remove a weight type associated with the vertices of the graph.See
Weights
for a complete documentation of the weights containers.If this index graph object was obtained from a regular
Graph
usingGraph.indexGraph()
, this method should not be called. Use the original graph instead.- Parameters:
key
- the key of the weights
-
getEdgesIWeights
public <T,WeightsT extends IWeights<T>> WeightsT getEdgesIWeights(String key)
Description copied from interface:IntGraph
Get the edges weights of some key.See
IWeights
for a complete documentation of the weights containers.- Type Parameters:
T
- The weight data typeWeightsT
- the weights container, used to avoid casts of containers of primitive types such asIWeightsInt
,IWeightsDouble
ect.- Parameters:
key
- key of the weights- Returns:
- edges weights of the key, or
null
if no container found with the specified key
-
getEdgesWeightsKeys
public Set<String> getEdgesWeightsKeys()
Description copied from interface:Graph
Get the keys of all the associated edges weights.See
Weights
for a complete documentation of the weights containers.- Returns:
- the keys of all the associated edges weights
-
removeEdgesWeights
public void removeEdgesWeights(String key)
Description copied from interface:IndexGraph
Remove a weight type associated with the edges of the graph.See
Weights
for a complete documentation of the weights containers.If this index graph object was obtained from a regular
Graph
usingGraph.indexGraph()
, this method should not be called. Use the original graph instead.- Parameters:
key
- the key of the weights
-
addVerticesWeights
public <T,WeightsT extends Weights<Integer,T>> WeightsT addVerticesWeights(String key, Class<? super T> type, T defVal)
Description copied from interface:IndexGraph
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
Weights
for a complete documentation of the weights containers.If this index graph object was obtained from a regular
Graph
usingGraph.indexGraph()
, this method should not be called. Use the original graph instead.- Type Parameters:
T
- The weight data typeWeightsT
- the weights container, used to avoid casts of containers of primitive types such asWeightsInt
,WeightsDouble
ect.- 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
-
addEdgesWeights
public <T,WeightsT extends Weights<Integer,T>> WeightsT addEdgesWeights(String key, Class<? super T> type, T defVal)
Description copied from interface:IndexGraph
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
Weights
for a complete documentation of the weights containers.If this index graph object was obtained from a regular
Graph
usingGraph.indexGraph()
, this method should not be called. Use the original graph instead.- Type Parameters:
T
- The weight data typeWeightsT
- the weights container, used to avoid casts of containers of primitive types such asWeightsInt
,WeightsDouble
ect.- 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
-
addVertexRemoveListener
public void addVertexRemoveListener(IndexRemoveListener listener)
Description copied from interface:IndexGraph
Adds a listener that will be called each time a vertex remove or swap is performed.An
IndexGraph
may 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
public void removeVertexRemoveListener(IndexRemoveListener listener)
Description copied from interface:IndexGraph
Removes a vertex remove listener.After a listener was added using
IndexGraph.addVertexRemoveListener(IndexRemoveListener)
, this method can remove it.- Parameters:
listener
- a remove listener that should be removed
-
addEdgeRemoveListener
public void addEdgeRemoveListener(IndexRemoveListener listener)
Description copied from interface:IndexGraph
Adds a listener that will be called each time a edge swap is performed.An
IndexGraph
may 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
public void removeEdgeRemoveListener(IndexRemoveListener listener)
Description copied from interface:IndexGraph
Removes an edge remove listener.After a listener was added using
IndexGraph.addEdgeRemoveListener(IndexRemoveListener)
, this method can remove it.- Parameters:
listener
- a remove listener that should be removed
-
isDirected
public boolean isDirected()
Description copied from interface:Graph
Checks whether the graph is directed.- Specified by:
isDirected
in interfaceGraph<Integer,Integer>
- Returns:
true
if the graph is directed, elsefalse
.
-
isAllowSelfEdges
public boolean isAllowSelfEdges()
Description copied from interface:Graph
Checks whether self edges are supported.Self edges are edges with the same source and target, namely a vertex with an edge to itself.
- Specified by:
isAllowSelfEdges
in interfaceGraph<Integer,Integer>
- Returns:
true
if the graph support self edges, elsefalse
.
-
isAllowParallelEdges
public boolean isAllowParallelEdges()
Description copied from interface:Graph
Checks whether parallel edges are supported.Parallel edges are multiple edges with identical source and target.
- Specified by:
isAllowParallelEdges
in interfaceGraph<Integer,Integer>
- Returns:
true
if the graph support parallel edges, elsefalse
.
-
getEdges
public IEdgeSet getEdges(int source, int target)
Description copied from interface:IntGraph
Get the edges whose source issource
and target istarget
.
-
-