graph-builder
Version:
A graph builder library for modeling abstract graph structures.
62 lines (61 loc) • 2.62 kB
TypeScript
import { AbstractGraphBuilder } from "./AbstractGraphBuilder";
import { ValueGraph } from "./ValueGraph";
import { ElementOrder } from "./ElementOrder";
import { MutableValueGraph } from "./MutableValueGraph";
/**
* A builder for constructing instances of {@link MutableValueGraph} with user-defined properties.
*
* @remarks
*
* A graph built by this class will have the following properties by default:
*
* - does not allow self-loops
* - orders {@link BaseGraph.nodes} in the order in which the elements were added
*
* Example of use:
*
* ```typescript
* const graph: MutableValueGraph<String, number> =
* ValueGraphBuilder.undirected().allowsSelfLoops(true).build();
* graph.putEdgeValue("San Francisco", "San Francisco", 0.0);
* graph.putEdgeValue("San Jose", "San Jose", 0.0);
* graph.putEdgeValue("San Francisco", "San Jose", 48.4);
* ```
*
* @public
*/
export declare class ValueGraphBuilder<N, V> extends AbstractGraphBuilder<N> {
/** Creates a new instance with the specified edge directionality. */
private constructor();
/** Returns a {@link ValueGraphBuilder} for building directed graphs. */
static directed<N, V>(): ValueGraphBuilder<N, V>;
/** Returns a {@link ValueGraphBuilder} for building undirected graphs. */
static undirected<N, V>(): ValueGraphBuilder<N, V>;
/**
* Returns a {@link ValueGraphBuilder} initialized with all properties queryable from
* `graph`.
*
* <p>The "queryable" properties are those that are exposed through the {@link ValueGraph}
* interface, such as {@link BaseGraph.isDirected}. Other properties, such as {@link
* ValueGraphBuilder.expectedNodeCount}, are not set in the new builder.
*/
static from<N, V>(graph: ValueGraph<N, V>): ValueGraphBuilder<N, V>;
/**
* 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): ValueGraphBuilder<N, V>;
/**
* Specifies the expected number of nodes in the graph.
*
* Throws an error if `expectedNodeCount` is negative.
*/
expectedNodeCount(expectedNodeCount: number): ValueGraphBuilder<N, V>;
/** Specifies the order of iteration for the elements of {@link BaseGraph.nodes}. */
nodeOrder(nodeOrder: ElementOrder<N>): ValueGraphBuilder<N, V>;
/**
* Returns an empty {@link MutableValueGraph} with the properties of this {@link
* ValueGraphBuilder}.
*/
build(): MutableValueGraph<N, V>;
}