Skip to main content

interface EdgeValuedGraphBase.Builder<N,V,Tp>

undocumented

Extends: ValuedGraphBase.Builder<N,V,Tp>

Implemented by: EdgeValuedGraphSorted.Builder<N,V>, EdgeValuedGraph.Builder<N,V>, EdgeValuedGraphHashed.Builder<N,V>

Type parameters

NameConstraintsDefaultDescription
Nundocumented
Vundocumented
TpEdgeValuedGraphBase.TypesEdgeValuedGraphBase.Typesundocumented

Properties

connectionSize

Returns the amount of connections in the graph.

Definition

readonly connectionSize: number;

example
ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
.connectionsSize
// => 2

Overrides

Builder.connectionSize

context

Returns the context associated to this collection instance.

Definition

readonly context: WithGraphValues<Tp, N, V>['context'];

Overrides

Builder.context

isEmpty

Returns true if there are no entries in the builder.

Definition

readonly isEmpty: boolean;

example
ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
.isEmpty
// => false

Overrides

Builder.isEmpty

nodeSize

Returns the amount of nodes in the graph.

Definition

readonly nodeSize: number;

example
ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
.nodeSize
// => 3

Overrides

Builder.nodeSize

Methods

addGraphElement

Adds the given element graph element to the graph.

Definition

addGraphElement(element: ValuedGraphElement<N, V>): boolean;

Parameters

NameTypeDescription
elementValuedGraphElement<N, V>
example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
b.addGraphElement([4]) // => true
b.addGraphElement([3, 1, 'c']) // => true
b.addGraphElement([1, 2, 'a']) // => false

Overrides

Builder.addGraphElement

addGraphElements

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

Definition

addGraphElements(elements: StreamSource<ValuedGraphElement<N, V>>): boolean;

Parameters

NameTypeDescription
elementsStreamSource<ValuedGraphElement<N, V>>
example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
b.addGraphElements([[4], [5]]) // => true
b.addGraphElements([[3, 1, 'c'], [1]]) // => true
b.addGraphElements([[1, 2, 'a'], [1]]) // => false

Overrides

Builder.addGraphElements

addNode

Adds the given node to the graph.

Definition

addNode(node: N): boolean;

Parameters

NameTypeDescription
nodeN
example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
b.addNode(6) // => true
b.addNode(1) // => false

Overrides

Builder.addNode

addNodes

Adds the given nodes to the builder.

Definition

addNodes(nodes: StreamSource<N>): boolean;

Parameters

NameTypeDescription
nodesStreamSource<N>
example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
b.addNodes([3, 4, 5]) // => true
b.addNodes([1, 2]) // => false

Overrides

Builder.addNodes

build

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

Definition

build(): WithGraphValues<Tp, N, V>['normal'];

example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
const g: ArrowValuedGraphHashed<number, string> = b.build()

Overrides

Builder.build

buildMapValues

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

Definition

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

Type parameters

NameDescription
V2

Parameters

NameTypeDescription
mapFun(value: V, node1: N, node2: N) => V2a function taking the value
example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
const g: ArrowValuedGraphHashed<number, string> = b.buildMapValues(v => v.toUpperCase())

Overrides

Builder.buildMapValues

connect

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

Definition

connect(node1: N, node2: N, value: V): boolean;

Parameters

NameTypeDescription
node1Nthe first connection node
node2Nthe second connection node
valueV
example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
b.connect(3, 1, 'c') // => true
b.connect(1, 2, 'a') // => false
b.connect(1, 2, 'z') // => true

Overrides

Builder.connect

connectAll

Adds the connections in given connections StreamSource to the graph.

Definition

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

Parameters

NameTypeDescription
connectionsStreamSource<WithGraphValues<Tp, N, V>['link']>
example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
b.connectAll([[1, 2, 'a'], [3, 1, 'c']]) // => true
b.connectAll([[1, 2, 'a']]) // => false

Overrides

Builder.connectAll

disconnect

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

Definition

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

Type parameters

NameDefaultDescription
UNN

Parameters

NameTypeDescription
node1RelatedTo<N, UN>the first connection node
node2RelatedTo<N, UN>
example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
b.disconnect(1, 2) // => true
b.disconnect(3, 4) // => false

Overrides

Builder.disconnect

disconnectAll

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

Definition

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

Type parameters

NameDefaultDescription
UNN

Parameters

NameTypeDescription
connectionsStreamSource<Link<RelatedTo<N, UN>>>
example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
b.disconnectAll([[1, 2], [3, 4]]) // => true
b.disconnectAll([[3, 4], [5, 6]]) // => false

Overrides

Builder.disconnectAll

getValue

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

Definitions

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

getValue<UN, O>(node1: RelatedTo<N, UN>, node2: RelatedTo<N, UN>, otherwise: OptLazy<O>): V | O;

Type parameters

NameDefaultDescription
UNN

Parameters

NameTypeDescription
node1RelatedTo<N, UN>the first connection node
node2RelatedTo<N, UN>the second connection node
example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
m.getValue(2, 3) // => 'b'
m.getValue(3, 4) // => undefined
m.getValue(2, 3, 'none') // => 'b'
m.getValue(3, 4, 'none') // => 'none'

Overrides

Builder.getValue

hasConnection

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

Definition

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

Type parameters

NameDefaultDescription
UNN

Parameters

NameTypeDescription
node1RelatedTo<N, UN>the first connection node
node2RelatedTo<N, UN>the second connection node
example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
b.hasConnection(1, 2) // => true
b.hasConnection(6, 7) // => false

Overrides

Builder.hasConnection

hasNode

Returns true if the graph contains the given node.

Definition

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

Type parameters

NameDefaultDescription
UNN

Parameters

NameTypeDescription
nodeRelatedTo<N, UN>the node to search
example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
b.hasNode(1) // => true
b.hasNode(6) // => false

Overrides

Builder.hasNode

modifyAt

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

Definition

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

Parameters

NameTypeDescription
node1Nthe first connection node
node2Nthe second connection node
options{
      ifNew?: OptLazyOr<V, Token>;
      ifExists?: (value: V, remove: Token) => V | Token;
    }
example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
b.modifyAt(3, 4, { ifNew: 'c' }) // => true
g.modifyAt(4, 5, { ifNew: (none) => 1 < 2 ? none : 'c' }) // => false
g.modifyAt(1, 2, { ifNew: 'a' }) // => false
g.modifyAt(1, 2, { ifExists: () => 'c' }) // => false
g.modifyAt(1, 2, { ifExists: (v) => v + 'z' }) // => true
g.modifyAt(2, 3, { ifExists: (v, remove) => v === 'a' ? v : remove })
// => true

Overrides

Builder.modifyAt

removeNode

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

Definition

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

Type parameters

NameDefaultDescription
UNN

Parameters

NameTypeDescription
nodeRelatedTo<N, UN>
example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
b.removeNode(1) // => true
b.removeNode(6) // => false

Overrides

Builder.removeNode

removeNodes

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

Definition

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

Type parameters

NameDefaultDescription
UNN

Parameters

NameTypeDescription
nodesStreamSource<RelatedTo<N, UN>>
example
const b = ArrowValuedGraphHashed
.of([[1, 2, 'a'], [2, 3, 'b']])
.toBuilder()
b.removeNodes([1, 6, 7]) // => true
b.removeNodes([6, 7]) // => false

Overrides

Builder.removeNodes