Interface IndexGraphFactory
-
- All Superinterfaces:
GraphFactory<Integer,Integer>,IntGraphFactory
public interface IndexGraphFactory extends IntGraphFactory
A factory for Index graphs.The factory can be used to create new empty graphs, with different options and capabilities. Few methods are available to optimize the graph implementation choice. The factory can also be used to create a copy of an existing graphs, with the same vertices and edges, with/without copying the vertices/edges weights.
Both the graph factory and
IndexGraphBuilderare used to create new graphs. The difference is that vertices and edges can be added to the builder, which is then used to construct non empty graphs, while the factory is only used to choose a graph implementation and create an empty graph.This interface is a specific version of
IntGraphFactoryforIndexGraph.- Author:
- Barak Ugav
- See Also:
directed(),undirected(),IndexGraph,IndexGraphBuilder
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.jgalgo.graph.GraphFactory
GraphFactory.Hint
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description IndexGraphFactoryaddHint(GraphFactory.Hint hint)Add a hint to this factory.default IndexGraphFactoryallowParallelEdges()Change the config of this factory so that the built graphs will support parallel edges.IndexGraphFactoryallowParallelEdges(boolean parallelEdges)Determine if graphs built by this factory should be support parallel edges.default IndexGraphFactoryallowSelfEdges()Change the config of this factory so that the built graphs will support self edges.IndexGraphFactoryallowSelfEdges(boolean selfEdges)Determine if graphs built by this factory should be support self edges.static IndexGraphFactorydirected()Create a directed index graph factory.IndexGraphFactoryexpectedEdgesNum(int expectedEdgesNum)Set the expected number of edges that will exist in the graph.IndexGraphFactoryexpectedVerticesNum(int expectedVerticesNum)Set the expected number of vertices that will exist in the graph.IndexGraphBuildernewBuilder()Create a new graph builder with the factory parameters.default IndexGraphBuildernewBuilderCopyOf(Graph<Integer,Integer> g)Create a new graph builder with the factory parameters initialized with an existing graph vertices and edges, without copying the weights.IndexGraphBuildernewBuilderCopyOf(Graph<Integer,Integer> g, boolean copyVerticesWeights, boolean copyEdgesWeights)Create a new graph builder with the factory parameters initialized with an existing graph vertices and edges, with/without copying the weights.default IndexGraphnewCopyOf(Graph<Integer,Integer> g)Create a copy of a given graph, with the same vertices and edges, without copying weights.IndexGraphnewCopyOf(Graph<Integer,Integer> g, boolean copyVerticesWeights, boolean copyEdgesWeights)Create a copy of a given graph, with the same vertices and edges, with/without copying weights.IndexGraphnewGraph()Create a new empty graph.default IndexGraphnewImmutableCopyOf(Graph<Integer,Integer> g)Create a new immutable copy of a given graph, with the same vertices and edges, without copying weights.IndexGraphnewImmutableCopyOf(Graph<Integer,Integer> g, boolean copyVerticesWeights, boolean copyEdgesWeights)Create a new immutable copy of a given graph, with the same vertices and edges, with/without copying weights.static IndexGraphFactorynewInstance(boolean directed)Create a new un/directed index graph factory.IndexGraphFactoryremoveHint(GraphFactory.Hint hint)Remove a hint from this factory.IndexGraphFactorysetDirected(boolean directed)Determine if graphs built by this factory should be directed.default IndexGraphFactorysetEdgeBuilder(IdBuilder<Integer> edgeBuilder)Deprecated.Index graphs does not support custom edge builderdefault IndexGraphFactorysetEdgeFactory(Supplier<? extends IdBuilder<Integer>> edgeFactory)Deprecated.Index graphs does not support custom edge builderdefault IndexGraphFactorysetOption(String key, Object value)[TL;DR Don't call me!] Set an option.default IndexGraphFactorysetVertexBuilder(IdBuilder<Integer> vertexBuilder)Deprecated.Index graphs does not support custom vertex builderdefault IndexGraphFactorysetVertexFactory(Supplier<? extends IdBuilder<Integer>> vertexFactory)Deprecated.Index graphs does not support custom vertex builderstatic IndexGraphFactoryundirected()Create an undirected index graph factory.
-
-
-
Method Detail
-
newGraph
IndexGraph newGraph()
Description copied from interface:GraphFactoryCreate a new empty graph.- Specified by:
newGraphin interfaceGraphFactory<Integer,Integer>- Specified by:
newGraphin interfaceIntGraphFactory- Returns:
- a new graph with the factory options
-
newCopyOf
default IndexGraph newCopyOf(Graph<Integer,Integer> g)
Description copied from interface:GraphFactoryCreate 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 mutable, 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 support self edges (ifGraphFactory.allowSelfEdges(boolean)was not called withtrue), attempting to create a copy of a graph that does contains self edges will result in an exception.For an immutable copy of a graph, see
GraphFactory.newImmutableCopyOf(Graph, boolean, boolean).- Specified by:
newCopyOfin interfaceGraphFactory<Integer,Integer>- Specified by:
newCopyOfin interfaceIntGraphFactory- 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
IndexGraph newCopyOf(Graph<Integer,Integer> g, boolean copyVerticesWeights, boolean copyEdgesWeights)
Description copied from interface:GraphFactoryCreate 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 mutable, with no side affects on the original graph.
Differing from
Graph.copy(boolean, 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 support self edges (ifGraphFactory.allowSelfEdges(boolean)was not called withtrue), attempting to create a copy of a graph that does contains self edges will result in an exception.For an immutable copy of a graph, see
GraphFactory.newImmutableCopyOf(Graph, boolean, boolean).- Specified by:
newCopyOfin interfaceGraphFactory<Integer,Integer>- Specified by:
newCopyOfin interfaceIntGraphFactory- Parameters:
g- the original graph to copycopyVerticesWeights- iftrue, the weights of the vertices will be copied to the new graphcopyEdgesWeights- iftrue, the weights of the 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
-
newImmutableCopyOf
default IndexGraph newImmutableCopyOf(Graph<Integer,Integer> g)
Description copied from interface:GraphFactoryCreate a new immutable 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 be immutable, with no side affects on the original graph.
Differing from
Graph.immutableCopy(), 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 support self edges (ifGraphFactory.allowSelfEdges(boolean)was not called withtrue), attempting to create a copy of a graph that does contains self edges will result in an exception.For a mutable copy of a graph, see
GraphFactory.newCopyOf(Graph, boolean, boolean).- Specified by:
newImmutableCopyOfin interfaceGraphFactory<Integer,Integer>- Specified by:
newImmutableCopyOfin interfaceIntGraphFactory- Parameters:
g- the original graph to copy- Returns:
- an identical immutable copy of the given graph, with the same vertices and edges, without the original graph weights
-
newImmutableCopyOf
IndexGraph newImmutableCopyOf(Graph<Integer,Integer> g, boolean copyVerticesWeights, boolean copyEdgesWeights)
Description copied from interface:GraphFactoryCreate a new immutable 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 be immutable, with no side affects on the original graph.
Differing from
Graph.immutableCopy(boolean, 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 support self edges (ifGraphFactory.allowSelfEdges(boolean)was not called withtrue), attempting to create a copy of a graph that does contains self edges will result in an exception.For a mutable copy of a graph, see
GraphFactory.newCopyOf(Graph, boolean, boolean).- Specified by:
newImmutableCopyOfin interfaceGraphFactory<Integer,Integer>- Specified by:
newImmutableCopyOfin interfaceIntGraphFactory- Parameters:
g- the original graph to copycopyVerticesWeights- iftrue, the weights of the vertices will be copied to the new graphcopyEdgesWeights- iftrue, the weights of the edges will be copied to the new graph- Returns:
- an identical immutable copy of the given graph, with the same vertices and edges, without the original graph weights
-
newBuilder
IndexGraphBuilder newBuilder()
Description copied from interface:GraphFactoryCreate a new graph builder with the factory parameters.The created builder can be used to add vertices and edges, and then build a (mutable or immutable) non empty graph, differing from the factory which only builds empty graphs. The capabilities such as un/directed, support of self edges, support of parallel edges, and hints such as expected number of vertices and edges, other hints, etc. are copied from the factory to the builder.
- Specified by:
newBuilderin interfaceGraphFactory<Integer,Integer>- Specified by:
newBuilderin interfaceIntGraphFactory- Returns:
- a new graph builder with the factory parameters
-
newBuilderCopyOf
default IndexGraphBuilder newBuilderCopyOf(Graph<Integer,Integer> g)
Create a new graph builder with the factory parameters 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.
The given graph vertices and edges must be
0,1,2,...,verticesNum-1and0,1,2,...,edgesNum-1respectively.- Specified by:
newBuilderCopyOfin interfaceGraphFactory<Integer,Integer>- Specified by:
newBuilderCopyOfin interfaceIntGraphFactory- Parameters:
g- a graph- Returns:
- a graph builder with the factory parameters initialized with the given graph vertices and edges, without the original graph vertices/edges weights.
- Throws:
IllegalArgumentException- if the vertices are not0,1,2,...,verticesNum-1or if the edges are not0,1,2,...,edgesNum-1
-
newBuilderCopyOf
IndexGraphBuilder newBuilderCopyOf(Graph<Integer,Integer> g, boolean copyVerticesWeights, boolean copyEdgesWeights)
Create a new graph builder with the factory parameters 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.
The given graph vertices and edges must be
0,1,2,...,verticesNum-1and0,1,2,...,edgesNum-1respectively.- Specified by:
newBuilderCopyOfin interfaceGraphFactory<Integer,Integer>- Specified by:
newBuilderCopyOfin interfaceIntGraphFactory- Parameters:
g- a graphcopyVerticesWeights- iftrue, the weights of the vertices will be copied from the graph to the buildercopyEdgesWeights- iftrue, the weights of the edges will be copied from the graph to the builder- Returns:
- a graph builder with the factory parameters initialized with the given graph vertices and edges, with/without the original graph vertices/edges weights.
- Throws:
IllegalArgumentException- if the vertices are not0,1,2,...,verticesNum-1or if the edges are not0,1,2,...,edgesNum-1
-
setDirected
IndexGraphFactory setDirected(boolean directed)
Description copied from interface:GraphFactoryDetermine if graphs built by this factory should be directed.Usually the factory will be created using either
GraphFactory.directed()orGraphFactory.undirected(), and there will be no need to call this method. However, it is sometimes useful use the same factory to build both directed and undirected graphs, and this method can be used to change the factory configuration. For example, a factory can be passed to a random graph generator, which can generated both directed and undirected graphs, depending on the generator parameters.- Specified by:
setDirectedin interfaceGraphFactory<Integer,Integer>- Specified by:
setDirectedin interfaceIntGraphFactory- Parameters:
directed- iftruegraphs built by this factory will be directed, else they will be undirected- Returns:
- this factory
-
allowSelfEdges
default IndexGraphFactory allowSelfEdges()
Description copied from interface:GraphFactoryChange the config of this factory so that the built graphs will support self edges.By default, graphs built by this factory will not support self edges.
- Specified by:
allowSelfEdgesin interfaceGraphFactory<Integer,Integer>- Specified by:
allowSelfEdgesin interfaceIntGraphFactory- Returns:
- this factory
-
allowSelfEdges
IndexGraphFactory allowSelfEdges(boolean selfEdges)
Description copied from interface:GraphFactoryDetermine if graphs built by this factory should be support self edges.By default, graphs built by this factory will not support self edges.
- Specified by:
allowSelfEdgesin interfaceGraphFactory<Integer,Integer>- Specified by:
allowSelfEdgesin interfaceIntGraphFactory- Parameters:
selfEdges- iftruegraphs built by this factory will support self edges, else they will not- Returns:
- this factory
-
allowParallelEdges
default IndexGraphFactory allowParallelEdges()
Description copied from interface:GraphFactoryChange the config of this factory so that the built graphs will support parallel edges.By default, graphs built by this factory will support parallel edges. The reason is that in order to enforce no parallel edges are added to the graph, an efficient lookup of edges (keyed by an edge's vertices) is required, which is an operation most graph algorithms do not use and therefore most implementations are not optimized for. See
GraphFactory.Hint.FastEdgeLookup.- Specified by:
allowParallelEdgesin interfaceGraphFactory<Integer,Integer>- Specified by:
allowParallelEdgesin interfaceIntGraphFactory- Returns:
- this factory
-
allowParallelEdges
IndexGraphFactory allowParallelEdges(boolean parallelEdges)
Description copied from interface:GraphFactoryDetermine if graphs built by this factory should be support parallel edges.By default, graphs built by this factory will support parallel edges. The reason is that in order to enforce no parallel edges are added to the graph, an efficient lookup of edges (keyed by an edge's vertices) is required, which is an operation most graph algorithms do not use and therefore most implementations are not optimized for. See
GraphFactory.Hint.FastEdgeLookup.- Specified by:
allowParallelEdgesin interfaceGraphFactory<Integer,Integer>- Specified by:
allowParallelEdgesin interfaceIntGraphFactory- Parameters:
parallelEdges- iftruegraphs built by this factory will support parallel edges, else they will not- Returns:
- this factory
-
expectedVerticesNum
IndexGraphFactory expectedVerticesNum(int expectedVerticesNum)
Description copied from interface:GraphFactorySet the expected number of vertices that will exist in the graph.- Specified by:
expectedVerticesNumin interfaceGraphFactory<Integer,Integer>- Specified by:
expectedVerticesNumin interfaceIntGraphFactory- Parameters:
expectedVerticesNum- the expected number of vertices in the graph- Returns:
- this factory
-
expectedEdgesNum
IndexGraphFactory expectedEdgesNum(int expectedEdgesNum)
Description copied from interface:GraphFactorySet the expected number of edges that will exist in the graph.- Specified by:
expectedEdgesNumin interfaceGraphFactory<Integer,Integer>- Specified by:
expectedEdgesNumin interfaceIntGraphFactory- Parameters:
expectedEdgesNum- the expected number of edges in the graph- Returns:
- this factory
-
setVertexBuilder
@Deprecated default IndexGraphFactory setVertexBuilder(IdBuilder<Integer> vertexBuilder)
Deprecated.Index graphs does not support custom vertex builderUnsupported operation, index graphs does not support custom vertex builder.- Specified by:
setVertexBuilderin interfaceGraphFactory<Integer,Integer>- Specified by:
setVertexBuilderin interfaceIntGraphFactory- Parameters:
vertexBuilder- the vertex builder, ornullif no vertex builder should be used- Returns:
- this factory
- Throws:
UnsupportedOperationException- always
-
setVertexFactory
@Deprecated default IndexGraphFactory setVertexFactory(Supplier<? extends IdBuilder<Integer>> vertexFactory)
Deprecated.Index graphs does not support custom vertex builderUnsupported operation, index graphs does not support custom vertex builder.- Specified by:
setVertexFactoryin interfaceGraphFactory<Integer,Integer>- Specified by:
setVertexFactoryin interfaceIntGraphFactory- Parameters:
vertexFactory- the vertex factory, ornullif no vertex builder should be used- Returns:
- this factory
- Throws:
UnsupportedOperationException- always
-
setEdgeBuilder
@Deprecated default IndexGraphFactory setEdgeBuilder(IdBuilder<Integer> edgeBuilder)
Deprecated.Index graphs does not support custom edge builderUnsupported operation, index graphs does not support custom edge builder.- Specified by:
setEdgeBuilderin interfaceGraphFactory<Integer,Integer>- Specified by:
setEdgeBuilderin interfaceIntGraphFactory- Parameters:
edgeBuilder- the edge builder, ornullif no edge builder should be used- Returns:
- this factory
- Throws:
UnsupportedOperationException- always
-
setEdgeFactory
@Deprecated default IndexGraphFactory setEdgeFactory(Supplier<? extends IdBuilder<Integer>> edgeFactory)
Deprecated.Index graphs does not support custom edge builderUnsupported operation, index graphs does not support custom edge builder.- Specified by:
setEdgeFactoryin interfaceGraphFactory<Integer,Integer>- Specified by:
setEdgeFactoryin interfaceIntGraphFactory- Parameters:
edgeFactory- the edge factory, ornullif no edge builder should be used- Returns:
- this factory
- Throws:
UnsupportedOperationException- always
-
addHint
IndexGraphFactory addHint(GraphFactory.Hint hint)
Description copied from interface:GraphFactoryAdd a hint to this factory.Hints do not change the behavior of the graphs built by this factory, by may affect performance.
- Specified by:
addHintin interfaceGraphFactory<Integer,Integer>- Specified by:
addHintin interfaceIntGraphFactory- Parameters:
hint- the hint to add- Returns:
- this factory
-
removeHint
IndexGraphFactory removeHint(GraphFactory.Hint hint)
Description copied from interface:GraphFactoryRemove a hint from this factory.Hints do not change the behavior of the graphs built by this factory, by may affect performance.
- Specified by:
removeHintin interfaceGraphFactory<Integer,Integer>- Specified by:
removeHintin interfaceIntGraphFactory- Parameters:
hint- the hint to remove- Returns:
- this factory
-
undirected
static IndexGraphFactory undirected()
Create an undirected index graph factory.- Returns:
- a new factory that can build undirected index graphs
-
directed
static IndexGraphFactory directed()
Create a directed index graph factory.- Returns:
- a new factory that can build directed index graphs
-
newInstance
static IndexGraphFactory newInstance(boolean directed)
Create a new un/directed index graph factory.- Parameters:
directed- whether the graphs created by the factory should be directed- Returns:
- a new factory that can build un/directed index graphs
-
setOption
default IndexGraphFactory setOption(String key, Object value)
Description copied from interface:GraphFactory[TL;DR Don't call me!] Set an option.The builder might support different options to customize its implementation. These options never change the behavior of the algorithm, only its internal implementation. The possible options are not exposed as 'public' because they are not part of the API and may change in the future.
These options are mainly for debug and benchmark purposes.
- Specified by:
setOptionin interfaceGraphFactory<Integer,Integer>- Specified by:
setOptionin interfaceIntGraphFactory- Parameters:
key- the option keyvalue- the option value- Returns:
- this builder
-
-