Skip to main content
Module

x/rimbu/graph/custom/index.ts>GraphBase.Builder

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
interface GraphBase.Builder
import { type GraphBase } from "https://deno.land/x/rimbu@0.14.0/graph/custom/index.ts";
const { Builder } = GraphBase;

Properties

readonly
context: WithGraphValues<Tp, N, unknown>["context"]

Returns the context associated to this collection instance.

readonly
isEmpty: boolean

Returns true if there are no entries in the builder.

readonly
nodeSize: number

Returns the amount of nodes in the graph.

readonly
connectionSize: number

Returns the amount of connections in the graph.

Methods

hasNode<UN = N>(node: RelatedTo<N, UN>): boolean

Returns true if the graph contains the given node.

hasConnection<UN = N>(node1: RelatedTo<N, UN>, node2: RelatedTo<N, UN>): boolean

Returns true if the graph has a connection between given nodes node1 and node2.

addNode(node: N): boolean

Adds the given node to the graph.

addNodes(nodes: StreamSource<N>): boolean

Adds the given nodes to the builder.

addGraphElement(element: GraphElement<N>): boolean

Adds the given element graph element to the builder, where a graph element is either a one-element tuple containing a node, or a two-element tuple containing two nodes indicating a connection.

addGraphElements(elements: StreamSource<GraphElement<N>>): boolean

Adds the graph elements in the given elements StreamSource to the graph.

removeNode<UN = N>(node: RelatedTo<N, UN>): boolean

Removes the given node, and any of its connections, from the graph.

removeNodes<UN = N>(nodes: StreamSource<RelatedTo<N, UN>>): boolean

Removes the given nodes, and any of their connections, from the graph.

connect(node1: N, node2: N): boolean

Adds a connection between node1 and node2 to the graph.

connectAll(connections: StreamSource<WithGraphValues<Tp, N, unknown>["link"]>): boolean

Adds the connections in given connections StreamSource to the graph.

connectIfNodesExist(node1: N, node2: N): boolean

Adds a connection between given node1 and node2 nodes only if both nodes exist in the graph.

disconnect<UN = N>(node1: RelatedTo<N, UN>, node2: RelatedTo<N, UN>): boolean

Removes the connection between given node1 and node2 if the connection was present.

disconnectAll<UN = N>(connections: StreamSource<Link<RelatedTo<N, UN>>>): boolean

Removes all connections from the given connections StreamSource from the graph.

build(): WithGraphValues<Tp, N, unknown>["normal"]

Returns an immutable Graph containing the links in this Builder instance.