graph-builder
Version:
A graph builder library for modeling abstract graph structures.
57 lines (56 loc) • 2.31 kB
TypeScript
import { AbstractGraphBuilder } from "./AbstractGraphBuilder";
import { Graph } from "./Graph";
import { ElementOrder } from "./ElementOrder";
import { MutableGraph } from "./MutableGraph";
/**
* A builder for constructing instances of {@link MutableGraph} with user-defined properties.
*
* @remarks
*
* A graph built by this class will have the following properties by default:
*
* <ul>
* <li>does not allow self-loops</li>
* <li>orders {@link BaseGraph.nodes} in the order in which the elements were added</li>
* </ul>
*
* Example of use:
*
* ```typescript
* const graph: MutableGraph<String> = GraphBuilder.undirected().allowsSelfLoops(true).build();
* graph.putEdge("bread", "bread");
* graph.putEdge("chocolate", "peanut butter");
* graph.putEdge("peanut butter", "jelly");
* ```
*
* @public
*/
export declare class GraphBuilder<N> extends AbstractGraphBuilder<N> {
/** Returns a {@link GraphBuilder} for building directed graphs. */
static directed<T>(): GraphBuilder<T>;
/** Returns a {@link GraphBuilder} for building undirected graphs. */
static undirected<T>(): GraphBuilder<T>;
/**
* Returns a {@link GraphBuilder} initialized with all properties queryable from `graph`.
*
* <p>The "queryable" properties are those that are exposed through the {@link Graph} interface,
* such as {@link BaseGraph.isDirected}. Other properties, such as {@link GraphBuilder.expectedNodeCount},
* are not set in the new builder.
*/
static from<T>(graph: Graph<T>): GraphBuilder<T>;
/**
* 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.
*/
allowsSelfLoops(allowsSelfLoops: boolean): GraphBuilder<N>;
/**
* Specifies the expected number of nodes in the graph.
*
* throws an error if `expectedNodeCount` is negative
*/
expectedNodeCount(expectedNodeCount: number): GraphBuilder<N>;
/** Specifies the order of iteration for the elements of {@link BaseGraph.nodes}. */
nodeOrder(nodeOrder: ElementOrder<N>): GraphBuilder<N>;
/** Returns an empty {@link MutableGraph} with the properties of this {@link GraphBuilder}. */
build(): MutableGraph<N>;
}