Interface IntGraphBuilder
-
- All Superinterfaces:
GraphBuilder<Integer,Integer>
- All Known Subinterfaces:
IndexGraphBuilder
public interface IntGraphBuilder extends GraphBuilder<Integer,Integer>
A builder for int graphs.The builder is used to construct non-empty int graphs. Differing from
IntGraphFactory
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.This interface is a specific version of
GraphBuilder
forIntGraph
.- Author:
- Barak Ugav
- See Also:
newUndirected()
,newDirected()
,IndexGraphBuilder
,IntGraphFactory
-
-
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.default void
addEdge(Integer source, Integer target, Integer edge)
Deprecated.int
addVertex()
Add a new vertex to the graph.void
addVertex(int vertex)
Add a new vertex to the graph, with user-chosen identifier.default void
addVertex(Integer vertex)
Deprecated.IntGraph
build()
Build a new immutable graph with the builder vertices and edges.IntGraph
buildMutable()
Build a new mutable graph with the builder vertices and edges.IntSet
edges()
Get the set of edges that were added to the graph.<T,WeightsT extends IWeights<T>>
WeightsTgetEdgesIWeights(String key)
Get the edges weights of some key.default <T,WeightsT extends Weights<Integer,T>>
WeightsTgetEdgesWeights(String key)
Get the edges weights of some key.<T,WeightsT extends IWeights<T>>
WeightsTgetVerticesIWeights(String key)
Get the vertices weights of some key.default <T,WeightsT extends Weights<Integer,T>>
WeightsTgetVerticesWeights(String key)
Get the vertices weights of some key.static IntGraphBuilder
newDirected()
Create a new builder that builds directed int graphs.static IntGraphBuilder
newFrom(IntGraph g)
Create a new builder initialized with an existing graph vertices and edges, without copying the weights.static IntGraphBuilder
newFrom(IntGraph g, boolean copyWeights)
Create a new builder initialized with an existing graph vertices and edges, with/without copying the weights.static IntGraphBuilder
newUndirected()
Create a new builder that builds undirected graphs.IntSet
vertices()
Get the set of vertices that were added to the graph.-
Methods inherited from interface com.jgalgo.graph.GraphBuilder
addEdgesWeights, addEdgesWeights, addVerticesWeights, addVerticesWeights, clear, expectedEdgesNum, expectedVerticesNum, getEdgesWeightsKeys, getVerticesWeightsKeys
-
-
-
-
Method Detail
-
vertices
IntSet vertices()
Description copied from interface:GraphBuilder
Get the set of vertices that were added to the graph.- Specified by:
vertices
in interfaceGraphBuilder<Integer,Integer>
- Returns:
- the graph vertices
-
edges
IntSet edges()
Description copied from interface:GraphBuilder
Get the set of edges that were added to the graph.- Specified by:
edges
in interfaceGraphBuilder<Integer,Integer>
- Returns:
- the graph edges
-
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
addVertex(int)
. Only one ofaddVertex()
andaddVertex(int)
can be used during the construction of a graph.- Returns:
- the new vertex identifier
-
addVertex
void addVertex(int vertex)
Add a new vertex to the graph, with user-chosen identifier.This function is similar to
addVertex()
, but let the user to choose the the identifier of the new vertex. Only one ofaddVertex()
andaddVertex(int)
can be used during the construction of a graph.- Parameters:
vertex
- the new vertex identifier
-
addVertex
@Deprecated default void addVertex(Integer vertex)
Deprecated.Description copied from interface:GraphBuilder
Add a new vertex to the graph.- Specified by:
addVertex
in interfaceGraphBuilder<Integer,Integer>
- Parameters:
vertex
- the new vertex
-
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
addEdge(int, int, int)
. Only one ofaddEdge(int, int)
andaddEdge(int, int, int)
can be used during the construction of a graph.- 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
addEdge(int, int)
, but let the user to choose the identifier of the new edge. Only one ofaddEdge(int, int)
andaddEdge(int, int, int)
can be used during the construction of a graph.- Parameters:
source
- the source vertex of the new edgetarget
- the target vertex of the new edgeedge
- the identifier of the new edge
-
addEdge
@Deprecated default void addEdge(Integer source, Integer target, Integer edge)
Deprecated.Description copied from interface:GraphBuilder
Add a new edge to the graph.- Specified by:
addEdge
in interfaceGraphBuilder<Integer,Integer>
- Parameters:
source
- the source vertex of the new edgetarget
- the target vertex of the new edgeedge
- the new edge
-
getVerticesIWeights
<T,WeightsT extends IWeights<T>> WeightsT getVerticesIWeights(String key)
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
-
getVerticesWeights
default <T,WeightsT extends Weights<Integer,T>> WeightsT getVerticesWeights(String key)
Description copied from interface:GraphBuilder
Get the vertices weights of some key.See
Weights
for a complete documentation of the weights containers.- Specified by:
getVerticesWeights
in interfaceGraphBuilder<Integer,Integer>
- 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 weights- Returns:
- vertices weights of the key, or
null
if no container found with the specified key
-
getEdgesIWeights
<T,WeightsT extends IWeights<T>> WeightsT getEdgesIWeights(String key)
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
-
getEdgesWeights
default <T,WeightsT extends Weights<Integer,T>> WeightsT getEdgesWeights(String key)
Description copied from interface:GraphBuilder
Get the edges weights of some key.See
Weights
for a complete documentation of the weights containers.- Specified by:
getEdgesWeights
in interfaceGraphBuilder<Integer,Integer>
- 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 weights- Returns:
- edges weights of the key, or
null
if no container found with the specified key
-
build
IntGraph build()
Description copied from interface:GraphBuilder
Build a new immutable graph with the builder vertices and edges.- Specified by:
build
in interfaceGraphBuilder<Integer,Integer>
- Returns:
- a new immutable graph with the vertices and edges that were added to the builder.
-
buildMutable
IntGraph buildMutable()
Description copied from interface:GraphBuilder
Build a new mutable graph with the builder vertices and edges.- Specified by:
buildMutable
in interfaceGraphBuilder<Integer,Integer>
- Returns:
- a new mutable graph with the vertices and edges that were added to the builder.
-
newUndirected
static IntGraphBuilder newUndirected()
Create a new builder that builds undirected graphs.- Returns:
- a new empty builder for undirected graphs
-
newDirected
static IntGraphBuilder newDirected()
Create a new builder that builds directed int graphs.- Returns:
- a new empty builder for directed graphs
-
newFrom
static IntGraphBuilder newFrom(IntGraph 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 IntGraphBuilder newFrom(IntGraph 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.
-
-