Interface GraphFactory
-
- All Superinterfaces:
com.jgalgo.internal.util.BuilderAbstract<GraphFactory>
public interface GraphFactory extends com.jgalgo.internal.util.BuilderAbstract<GraphFactory>
A factory forGraph
objects.- Author:
- Barak Ugav
- See Also:
newDirected()
,newUndirected()
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
GraphFactory.Hint
Hints for a graph factory.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description GraphFactory
addHint(GraphFactory.Hint hint)
Add a hint to this factory.GraphFactory
allowParallelEdges(boolean parallelEdges)
Determine if graphs built by this factory should be support parallel edges.GraphFactory
allowSelfEdges(boolean selfEdges)
Determine if graphs built by this factory should be support self edges.GraphFactory
expectedEdgesNum(int expectedEdgesNum)
Set the expected number of edges that will exist in the graph.GraphFactory
expectedVerticesNum(int expectedVerticesNum)
Set the expected number of vertices that will exist in the graph.default Graph
newCopyOf(Graph g)
Create a copy of a given graph, with the same vertices and edges, without copying weights.Graph
newCopyOf(Graph g, boolean copyWeights)
Create a copy of a given graph, with the same vertices and edges, with/without copying weights.static GraphFactory
newDirected()
Create a directed graph factory.static GraphFactory
newFrom(Graph g)
Create a new graph factory based on a given implementation.Graph
newGraph()
Create a new empty graph.static GraphFactory
newUndirected()
Create an undirected graph factory.GraphFactory
removeHint(GraphFactory.Hint hint)
Remove a hint from this factory.GraphFactory
setDirected(boolean directed)
Determine if graphs built by this factory should be directed or not.
-
-
-
Method Detail
-
newGraph
Graph newGraph()
Create a new empty graph.- Returns:
- a new graph with the factory options
-
newCopyOf
default Graph newCopyOf(Graph g)
Create a copy of a given graph, with the same vertices and edges, without copying weights.An identical copy of the given graph will be created, with the same vertices and edges, without copying the vertices/edges weights. The returned Graph will always be modifiable, with no side affects on the original graph.
Differing from
Graph.copy()
, the capabilities of the new graph are determined by the factory configuration, rather than copied from the given graph. Note for example that if the factory chooses to use an implementation that does not (have to) support self edges (ifallowSelfEdges(boolean)
was not called withtrue
), attempting to create a copy of a graph that does contains self edges will result in an exception.- Parameters:
g
- the original graph to copy- Returns:
- an identical copy of the given graph, with the same vertices and edges, without the original graph weights
-
newCopyOf
Graph newCopyOf(Graph g, boolean copyWeights)
Create a copy of a given graph, with the same vertices and edges, with/without copying weights.An identical copy of the given graph will be created, with the same vertices and edges, with/without copying the vertices/edges weights. The returned Graph will always be modifiable, with no side affects on the original graph.
Differing from
Graph.copy(boolean)
, the capabilities of the new graph are determined by the factory configuration, rather than copied from the given graph. Note for example that if the factory chooses to use an implementation that does not (have to) support self edges (ifallowSelfEdges(boolean)
was not called withtrue
), attempting to create a copy of a graph that does contains self edges will result in an exception.- Parameters:
g
- the original graph to copycopyWeights
- 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 the original graph weights
-
setDirected
GraphFactory setDirected(boolean directed)
Determine if graphs built by this factory should be directed or not.- Parameters:
directed
- iftrue
, graphs built by this factory will be directed- Returns:
- this factory
-
allowSelfEdges
GraphFactory allowSelfEdges(boolean selfEdges)
Determine if graphs built by this factory should be support self edges.- Parameters:
selfEdges
- iftrue
, graphs built by this factory will support self edges- Returns:
- this factory
-
allowParallelEdges
GraphFactory allowParallelEdges(boolean parallelEdges)
Determine if graphs built by this factory should be support parallel edges.- Parameters:
parallelEdges
- iftrue
, graphs built by this factory will support parallel edges- Returns:
- this factory
-
expectedVerticesNum
GraphFactory expectedVerticesNum(int expectedVerticesNum)
Set the expected number of vertices that will exist in the graph.- Parameters:
expectedVerticesNum
- the expected number of vertices in the graph- Returns:
- this factory
-
expectedEdgesNum
GraphFactory expectedEdgesNum(int expectedEdgesNum)
Set the expected number of edges that will exist in the graph.- Parameters:
expectedEdgesNum
- the expected number of edges in the graph- Returns:
- this factory
-
addHint
GraphFactory addHint(GraphFactory.Hint hint)
Add a hint to this factory.Hints do not change the behavior of the graphs built by this factory, by may affect performance.
- Parameters:
hint
- the hint to add- Returns:
- this factory
-
removeHint
GraphFactory removeHint(GraphFactory.Hint hint)
Remove a hint from this factory.Hints do not change the behavior of the graphs built by this factory, by may affect performance.
- Parameters:
hint
- the hint to remove- Returns:
- this factory
-
newUndirected
static GraphFactory newUndirected()
Create an undirected graph factory.This is the recommended way to instantiate a new undirected graph.
- Returns:
- a new factory that can build undirected graphs
-
newDirected
static GraphFactory newDirected()
Create a directed graph factory.This is the recommended way to instantiate a new directed graph.
- Returns:
- a new factory that can build directed graphs
-
newFrom
static GraphFactory newFrom(Graph g)
Create a new graph factory based on a given implementation.The new factory will build graphs with the same capabilities (inclusive) as the given graph, possibly choosing to use a similar implementation. The factory will NOT copy the graph itself (the vertices, edges and weights), for such use case see
Graph.copy()
ornewCopyOf(Graph)
.- Parameters:
g
- a graph from which the factory should copy its capabilities (inclusive)- Returns:
- a new graph factory that will create graphs with the same capabilities (inclusive) of the given graph
-
-