Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/graph/custom/valued/interface/generic/valued-graph-base.ts>ValuedGraphBase.Builder

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

Properties

readonly
context: WithGraphValues<Tp, N, V>["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.

getValue<UN = N>(node1: RelatedTo<N, UN>, node2: RelatedTo<N, UN>): V | undefined

Returns the value associated with the connection between node1 and node2, or given otherwise value if the key is not in the collection.

getValue<UN, O>(
node1: RelatedTo<N, UN>,
node2: RelatedTo<N, UN>,
otherwise: OptLazy<O>,
): V | O
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: ValuedGraphElement<N, V>): boolean

Adds the given element graph element to the graph.

addGraphElements(elements: StreamSource<ValuedGraphElement<N, V>>): 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,
value: V,
): boolean

Adds a connection between node1 and node2 to the graph with given value.

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

Adds the connections in given connections StreamSource to the graph.

modifyAt(
node1: N,
node2: N,
options: { ifNew?: OptLazyOr<V, Token>; ifExists?: (value: V, remove: Token) => V | Token; },
): boolean

Modifies the graph at the connection between given node1 and node2 modified according to given options.

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, V>["normal"]

Returns an immutable graph containing the nodes and connections of this builder.

buildMapValues<V2>(mapFun: (
value: V,
node1: N,
node2: N,
) => V2
): WithGraphValues<Tp, N, V2>["normal"]

Returns an immutable graph containing the nodes and connections of this builder, where the values are mapped using the given mapFun function.