Home > graph-builder > GraphBuilder
A builder for constructing instances of MutableGraph with user-defined properties.
Method | Access Modifier | Returns | Description |
---|---|---|---|
allowsSelfLoops(allowsSelfLoops) |
GraphBuilder<N> |
Specifies whether the graph will allow self-loops (edges that connect a node to itself). Attempting to add a self-loop to a graph that does not allow them will throw an error. | |
build() |
MutableGraph<N> |
Returns an empty MutableGraph with the properties of this GraphBuilder. | |
directed() |
GraphBuilder<T> |
Returns a GraphBuilder for building directed graphs. | |
expectedNodeCount(expectedNodeCount) |
GraphBuilder<N> |
Specifies the expected number of nodes in the graph. throws an error if |
|
from(graph) |
GraphBuilder<T> |
Returns a GraphBuilder initialized with all properties queryable from graph .The "queryable" properties are those that are exposed through the Graph interface, such as BaseGraph.isDirected. Other properties, such as GraphBuilder.expectedNodeCount, are not set in the new builder. |
|
nodeOrder(nodeOrder) |
GraphBuilder<N> |
Specifies the order of iteration for the elements of BaseGraph.nodes. | |
undirected() |
GraphBuilder<T> |
Returns a GraphBuilder for building undirected graphs. |
A graph built by this class will have the following properties by default:
- does not allow self-loops
- orders [BaseGraph.nodes](./graph-builder.basegraph.nodes.md) in the order in which the elements were added
Example of use:
const graph: MutableGraph<String> = GraphBuilder.undirected().allowsSelfLoops(true).build();
graph.putEdge("bread", "bread");
graph.putEdge("chocolate", "peanut butter");
graph.putEdge("peanut butter", "jelly");