Interface IndexGraphBuilder
-
- All Superinterfaces:
GraphBuilder<Integer,Integer>
,IntGraphBuilder
public interface IndexGraphBuilder extends IntGraphBuilder
A builder for Index graphs.The builder is used to construct non-empty index graphs. Differing from
IndexGraphFactory
which create new empty graphs, the builder is used to add vertices and edges before actually creating the graph. This capability is required to create immutable graphs, but can also be used to build mutable graph and may gain a performance boost compared to creating an empty graph and adding the same vertices and edges.- Author:
- Barak Ugav
- See Also:
newUndirected()
,newDirected()
,IntGraphBuilder
,IndexGraphFactory
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
IndexGraphBuilder.ReIndexedGraph
A result object of re-indexing and building a graph operation.static interface
IndexGraphBuilder.ReIndexingMap
A map of indices, mapping an original index to a re-indexed index.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description int
addEdge(int source, int target)
Add a new edge to the graph.void
addEdge(int source, int target, int edge)
Add a new edge to the graph, with user-chosen identifier.int
addVertex()
Add a new vertex to the graph.default void
addVertex(int vertex)
Deprecated.IndexGraph
build()
Build a new immutable graph with the builder vertices and edges.IndexGraph
buildMutable()
Build a new mutable graph with the builder vertices and edges.static IndexGraphBuilder
newDirected()
Create a new builder that builds directed graphs.static IndexGraphBuilder
newFrom(IndexGraph g)
Create a new builder initialized with an existing graph vertices and edges, without copying the weights.static IndexGraphBuilder
newFrom(IndexGraph g, boolean copyWeights)
Create a new builder initialized with an existing graph vertices and edges, with/without copying the weights.static IndexGraphBuilder
newUndirected()
Create a new builder that builds undirected graphs.IndexGraphBuilder.ReIndexedGraph
reIndexAndBuild(boolean reIndexVertices, boolean reIndexEdges)
Re-Index the vertices/edges and build a new immutable graph with the new indexing.IndexGraphBuilder.ReIndexedGraph
reIndexAndBuildMutable(boolean reIndexVertices, boolean reIndexEdges)
Re-Index the vertices/edges and build a new mutable graph with the new indexing.-
Methods inherited from interface com.jgalgo.graph.GraphBuilder
addEdgesWeights, addEdgesWeights, addVerticesWeights, addVerticesWeights, clear, expectedEdgesNum, expectedVerticesNum, getEdgesWeightsKeys, getVerticesWeightsKeys
-
Methods inherited from interface com.jgalgo.graph.IntGraphBuilder
addEdge, addVertex, edges, getEdgesIWeights, getEdgesWeights, getVerticesIWeights, getVerticesWeights, vertices
-
-
-
-
Method Detail
-
addVertex
int addVertex()
Add a new vertex to the graph.The builder will choose identifier not used for any existing vertex, and will return it. It is also possible to add a new vertex and choose its identifier by using
IntGraphBuilder.addVertex(int)
. Only one ofIntGraphBuilder.addVertex()
andIntGraphBuilder.addVertex(int)
can be used during the construction of a graph.As the built graph is an Index graph, the vertices must be
0,1,2,...,verticesNum-1
and user-chosen IDs are not supported. A new vertex will be assigned ID of valuevertices().size()
.- Specified by:
addVertex
in interfaceIntGraphBuilder
- Returns:
- the new vertex identifier
-
addVertex
@Deprecated default void addVertex(int vertex)
Deprecated.Add a new vertex to the graph, with user-chosen identifier.This function is similar to
IntGraphBuilder.addVertex()
, but let the user to choose the the identifier of the new vertex. Only one ofIntGraphBuilder.addVertex()
andIntGraphBuilder.addVertex(int)
can be used during the construction of a graph.- Specified by:
addVertex
in interfaceIntGraphBuilder
- Parameters:
vertex
- the new vertex identifier- Throws:
UnsupportedOperationException
- always
-
addEdge
int addEdge(int source, int target)
Add a new edge to the graph.The builder will choose identifier not used for any existing edge, and will return it. It is also possible to add a new edge and choose its identifier by using
IntGraphBuilder.addEdge(int, int, int)
. Only one ofIntGraphBuilder.addEdge(int, int)
andIntGraphBuilder.addEdge(int, int, int)
can be used during the construction of a graph.As the built graph is an Index graph, the edges must be
0,1,2,...,edgesNum-1
. A new edge will be assigned ID of valueedges().size()
.It is possible to construct a graph by inserting the edges in a different order than their indices (IDs), by using
addEdge(int, int, int)
in which the ID of the inserted edge is specified along with the source and target vertices. If this method is used, the set of edges will be validated when a new graph is created, and it must be equal0,1,2,...,edgesNum-1
.- Specified by:
addEdge
in interfaceIntGraphBuilder
- Parameters:
source
- the source vertex of the new edgetarget
- the target vertex of the new edge- Returns:
- the new edge identifier
-
addEdge
void addEdge(int source, int target, int edge)
Add a new edge to the graph, with user-chosen identifier.This function is similar to
IntGraphBuilder.addEdge(int, int)
, but let the user to choose the identifier of the new edge. Only one ofIntGraphBuilder.addEdge(int, int)
andIntGraphBuilder.addEdge(int, int, int)
can be used during the construction of a graph.As the built graph is an Index graph, the edges must be
0,1,2,...,edgesNum-1
. This constraint is validated when the graph is actually created by the builder.- Specified by:
addEdge
in interfaceIntGraphBuilder
- Parameters:
source
- the source vertex of the new edgetarget
- the target vertex of the new edgeedge
- the identifier of the new edge
-
build
IndexGraph build()
Description copied from interface:GraphBuilder
Build a new immutable graph with the builder vertices and edges.- Specified by:
build
in interfaceGraphBuilder<Integer,Integer>
- Specified by:
build
in interfaceIntGraphBuilder
- Returns:
- a new immutable graph with the vertices and edges that were added to the builder.
-
buildMutable
IndexGraph buildMutable()
Description copied from interface:GraphBuilder
Build a new mutable graph with the builder vertices and edges.- Specified by:
buildMutable
in interfaceGraphBuilder<Integer,Integer>
- Specified by:
buildMutable
in interfaceIntGraphBuilder
- Returns:
- a new mutable graph with the vertices and edges that were added to the builder.
-
reIndexAndBuild
IndexGraphBuilder.ReIndexedGraph reIndexAndBuild(boolean reIndexVertices, boolean reIndexEdges)
Re-Index the vertices/edges and build a new immutable graph with the new indexing.Re-indexing is the operation of assigning new indices to the vertices/edges. By re-indexing the vertices/edges, the performance of accessing/iterating over the graph vertices/edges may increase, for example if a more cache friendly indexing exists.
Note that this method is not required to re-index the vertices (edges) if
reIndexVertices
(reIndexEdges
) istrue
, it is simply allowed to. Whether or not a re-indexing was performed can be checked via theIndexGraphBuilder.ReIndexedGraph
return value.- Parameters:
reIndexVertices
- iftrue
, the implementation is allowed to (note that it is not required) to re-index the vertices of the graph. Iffalse
, the original vertices identifiers are used. Whether or not re-indexing was performed can be checked viaIndexGraphBuilder.ReIndexedGraph.verticesReIndexing()
.reIndexEdges
- iftrue
, the implementation is allowed to (note that it is not required) to re-index the edges of the graph. Iffalse
, the original edges identifiers are used. Whether or not re-indexing was performed can be checked viaIndexGraphBuilder.ReIndexedGraph.edgesReIndexing()
.- Returns:
- the re-indexed immutable graph, along with the re-indexing mapping to the original indices
-
reIndexAndBuildMutable
IndexGraphBuilder.ReIndexedGraph reIndexAndBuildMutable(boolean reIndexVertices, boolean reIndexEdges)
Re-Index the vertices/edges and build a new mutable graph with the new indexing.Re-indexing is the operation of assigning new indices to the vertices/edges. By re-indexing the vertices/edges, the performance of accessing/iterating over the graph vertices/edges may increase, for example if a more cache friendly indexing exists.
Note that this method is not required to re-index the vertices (edges) if
reIndexVertices
(reIndexEdges
) istrue
, it is simply allowed to. Whether or not a re-indexing was performed can be checked via theIndexGraphBuilder.ReIndexedGraph
return value.- Parameters:
reIndexVertices
- iftrue
, the implementation is allowed to (note that it is not required) to re-index the vertices of the graph. Iffalse
, the original vertices identifiers are used. Whether or not re-indexing was performed can be checked viaIndexGraphBuilder.ReIndexedGraph.verticesReIndexing()
.reIndexEdges
- iftrue
, the implementation is allowed to (note that it is not required) to re-index the edges of the graph. Iffalse
, the original edges identifiers are used. Whether or not re-indexing was performed can be checked viaIndexGraphBuilder.ReIndexedGraph.edgesReIndexing()
.- Returns:
- the re-indexed mutable graph, along with the re-indexing mapping to the original indices
-
newUndirected
static IndexGraphBuilder newUndirected()
Create a new builder that builds undirected graphs.- Returns:
- a new empty builder for undirected graphs
-
newDirected
static IndexGraphBuilder newDirected()
Create a new builder that builds directed graphs.- Returns:
- a new empty builder for directed graphs
-
newFrom
static IndexGraphBuilder newFrom(IndexGraph g)
Create a new builder initialized with an existing graph vertices and edges, without copying the weights.If the given graph is directed, the new builder will build directed graphs, and similarly for undirected graphs.
- Parameters:
g
- a graph- Returns:
- a builder initialized with the given graph vertices and edges, without the original graph vertices/edges weights.
-
newFrom
static IndexGraphBuilder newFrom(IndexGraph g, boolean copyWeights)
Create a new builder initialized with an existing graph vertices and edges, with/without copying the weights.If the given graph is directed, the new builder will build directed graphs, and similarly for undirected graphs.
- Parameters:
g
- a graphcopyWeights
- iftrue
, the weights of the vertices and edges will be copied to the new graph- Returns:
- a builder initialized with the given graph vertices and edges, with/without the original graph vertices/edges weights.
-
-