Class GraphBaseWithEdgeEndpointsContainer
- java.lang.Object
-
- com.jgalgo.graph.GraphBaseWithEdgeEndpointsContainer
-
-
Method Summary
All Methods Instance Methods Concrete Methods Default Methods Modifier and Type Method Description intaddEdge(int source, int target)Add a new edge to the graph.voidaddEdgeRemoveListener(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.intaddVertex()Add a new vertex to the graph.voidaddVertexRemoveListener(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.voidclear()Clear the graph completely by removing all vertices and edges.voidclearEdges()Remove all the edges from the graph.default intedgeEndpoint(int edge, int endpoint)Get the other end-point of an edge.long[]edgeEndpoints()com.jgalgo.graph.GraphElementSetedges()Get the set of all edges of the graph.default intedgeSource(int edge)Get the source vertex of an edge.default intedgeTarget(int edge)Get the target vertex of an edge.booleanequals(Object other)IEdgeSetgetEdges(int source, int target)Get the edges whose source issourceand 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.inthashCode()booleanisAllowParallelEdges()Checks whether parallel edges are supported.booleanisAllowSelfEdges()Checks whether self edges are supported.booleanisDirected()Checks whether the graph is directed.voidremoveEdge(int edge)Remove an edge from the graph.voidremoveEdgeRemoveListener(IndexRemoveListener listener)Removes an edge remove listener.voidremoveEdgesWeights(String key)Remove a weight type associated with the edges of the graph.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.default voidreplaceEdgeEndpoint(int edge, int oldEndpoint, int newEndpoint)default voidreplaceEdgeSource(int edge, int newSource)default voidreplaceEdgeTarget(int edge, int newTarget)default voidsetEndpoints(int edge, int source, int target)StringtoString()com.jgalgo.graph.GraphElementSetvertices()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:IndexGraphAdd 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.- Specified by:
addEdgein interfaceIndexGraph- Specified by:
addEdgein interfaceIntGraph- Parameters:
source- a source vertextarget- a target vertex- Returns:
- the new edge identifier
-
clearEdges
public void clearEdges()
Description copied from interface:IndexGraphRemove 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>- Specified by:
clearEdgesin 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:IntGraphGet 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:
edgeEndpointin 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:IntGraphGet 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:
edgeSourcein interfaceIntGraph- Parameters:
edge- the edge identifier- Returns:
- the edge source vertex
-
edgeTarget
public default int edgeTarget(int edge)
Description copied from interface:IntGraphGet 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:
edgeTargetin 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:IndexGraphGet 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:IndexGraphGet 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:IndexGraphAdd 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.- Returns:
- the new vertex identifier
-
removeVertex
public final void removeVertex(int vertex)
Description copied from interface:IndexGraphRemove 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
GraphusingGraph.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:IndexGraphRemove 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
GraphusingGraph.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:IndexGraphClear 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.
-
getVerticesIWeights
public <T,WeightsT extends IWeights<T>> WeightsT getVerticesIWeights(String key)
Description copied from interface:IntGraphGet the vertices weights of some key.See
IWeightsfor 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,IWeightsDoubleect.- Parameters:
key- key of the weights- Returns:
- vertices weights of the key, or
nullif no container found with the specified key
-
getVerticesWeightsKeys
public Set<String> getVerticesWeightsKeys()
Description copied from interface:GraphGet the keys of all the associated vertices weights.See
Weightsfor 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:IndexGraphRemove 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.- Parameters:
key- the key of the weights
-
getEdgesIWeights
public <T,WeightsT extends IWeights<T>> WeightsT getEdgesIWeights(String key)
Description copied from interface:IntGraphGet the edges weights of some key.See
IWeightsfor 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,IWeightsDoubleect.- Parameters:
key- key of the weights- Returns:
- edges weights of the key, or
nullif no container found with the specified key
-
getEdgesWeightsKeys
public Set<String> getEdgesWeightsKeys()
Description copied from interface:GraphGet the keys of all the associated edges weights.See
Weightsfor 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:IndexGraphRemove 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.- 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:IndexGraphAdd 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.- 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
-
addEdgesWeights
public <T,WeightsT extends Weights<Integer,T>> WeightsT addEdgesWeights(String key, Class<? super T> type, T defVal)
Description copied from interface:IndexGraphAdd 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.- 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
-
addVertexRemoveListener
public void addVertexRemoveListener(IndexRemoveListener listener)
Description copied from interface:IndexGraphAdds 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
public void removeVertexRemoveListener(IndexRemoveListener listener)
Description copied from interface:IndexGraphRemoves 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:IndexGraphAdds 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
public void removeEdgeRemoveListener(IndexRemoveListener listener)
Description copied from interface:IndexGraphRemoves 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:GraphChecks whether the graph is directed.- Specified by:
isDirectedin interfaceGraph<Integer,Integer>- Returns:
trueif the graph is directed, elsefalse.
-
isAllowSelfEdges
public boolean isAllowSelfEdges()
Description copied from interface:GraphChecks 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:
isAllowSelfEdgesin interfaceGraph<Integer,Integer>- Returns:
trueif the graph support self edges, elsefalse.
-
isAllowParallelEdges
public boolean isAllowParallelEdges()
Description copied from interface:GraphChecks whether parallel edges are supported.Parallel edges are multiple edges with identical source and target.
- Specified by:
isAllowParallelEdgesin interfaceGraph<Integer,Integer>- Returns:
trueif the graph support parallel edges, elsefalse.
-
getEdges
public IEdgeSet getEdges(int source, int target)
Description copied from interface:IntGraphGet the edges whose source issourceand target istarget.
-
-