interface GraphBase.Builder<N,Tp>
undocumented
Implemented by: ArrowGraphBase.Builder<N,Tp>, EdgeGraphBase.Builder<N,Tp>
Type parameters
| Name | Constraints | Default | Description |
|---|---|---|---|
| N | undocumented | ||
| Tp | GraphBase.Types | GraphBase.Types | undocumented |
Properties
connectionSize
Returns the amount of connections in the graph.
connectionSizeDefinition
readonly connectionSize: number;
ArrowGraphHashed
.of([[1, 2], [2, 3]])
.toBuilder()
.connectionsSize
// => 2
context
Returns the context associated to this collection instance.
contextcontext associated to this collection instance.Definition
readonly context: WithGraphValues<Tp, N, unknown>['context'];
isEmpty
Returns true if there are no entries in the builder.
isEmptyDefinition
readonly isEmpty: boolean;
ArrowGraphHashed
.of([[1, 2], [2, 3]])
.toBuilder()
.isEmpty
// => false
nodeSize
Returns the amount of nodes in the graph.
nodeSizeDefinition
readonly nodeSize: number;
ArrowGraphHashed
.of([[1, 2], [2, 3]])
.toBuilder()
.nodeSize
// => 3
Methods
addGraphElement
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.
addGraphElementelement 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.Definition
addGraphElement(element: GraphElement<N>): boolean;
Parameters
| Name | Type | Description |
|---|---|---|
element | GraphElement<N> |
const b = ArrowGraphHashed
.of([[1, 2], [2, 3]])
.toBuilder()
b.addGraphElement([1]) // => false
b.addGraphElement([4]) // => true
b.addGraphElement([2, 3]) // => false
b.addGraphElement([4, 1]) // => true
addGraphElements
Adds the graph elements in the given elements StreamSource to the graph.
addGraphElementselements StreamSource to the graph.Definition
addGraphElements(elements: StreamSource<GraphElement<N>>): boolean;
Parameters
| Name | Type | Description |
|---|---|---|
elements | StreamSource<GraphElement<N>> |
const b = ArrowGraphHashed
.of([[1, 2], [2, 3]])
.toBuilder()
b.addGraphElements([[4], [5]]) // => true
b.addGraphElements([[3, 1], [1]]) // => true
b.addGraphElements([[1, 2], [1]]) // => false
addNode
Adds the given node to the graph.
addNodenode to the graph.addNodes
Adds the given nodes to the builder.
addNodesnodes to the builder.Definition
addNodes(nodes: StreamSource<N>): boolean;
Parameters
| Name | Type | Description |
|---|---|---|
nodes | StreamSource<N> |
const b = ArrowGraphHashed
.of([[1, 2], [2, 3]])
.toBuilder()
b.addNodes([3, 4, 5]) // => true
b.addNodes([1, 2]) // => false
build
Returns an immutable Graph containing the links in this Builder instance.
buildDefinition
build(): WithGraphValues<Tp, N, unknown>['normal'];
const b = ArrowGraphHashed.builder<number, number>()
b.connect(1, 2)
b.addNode(3)
const g = b.build()
console.log(g.toArray())
// => [[1, 2], [3]]
connect
Adds a connection between node1 and node2 to the graph.
connectnode1 and node2 to the graph.connectAll
Adds the connections in given connections StreamSource to the graph.
connectAllconnections StreamSource to the graph.Definition
connectAll(connections: StreamSource<WithGraphValues<Tp, N, unknown>['link']>): boolean;
Parameters
| Name | Type | Description |
|---|---|---|
connections | StreamSource<WithGraphValues<Tp, N, unknown>['link']> |
const b = ArrowGraphHashed
.of([[1, 2], [2, 3]])
.toBuilder()
b.connectAll([[1, 2], [3, 1]]) // => true
b.connectAll([[1, 2]]) // => false
connectIfNodesExist
Returns true if the graph has changed
connectIfNodesExistdisconnect
Removes the connection between given node1 and node2 if the connection was present.
disconnectnode1 and node2 if the connection was present.Definition
disconnect<UN = N>(node1: RelatedTo<N, UN>, node2: RelatedTo<N, UN>): boolean;
Type parameters
| Name | Default | Description |
|---|---|---|
| UN | N |
Parameters
| Name | Type | Description |
|---|---|---|
node1 | RelatedTo<N, UN> | the first connection node |
node2 | RelatedTo<N, UN> |
const b = ArrowGraphHashed
.of([[1, 2], [2, 3]])
.toBuilder()
b.disconnect(1, 2) // => true
b.disconnect(3, 4) // => false
disconnectAll
Removes all connections from the given connections StreamSource from the graph.
disconnectAllconnections StreamSource from the graph.Definition
disconnectAll<UN = N>(connections: StreamSource<Link<RelatedTo<N, UN>>>): boolean;
Type parameters
| Name | Default | Description |
|---|---|---|
| UN | N |
Parameters
| Name | Type | Description |
|---|---|---|
connections | StreamSource<Link<RelatedTo<N, UN>>> |
const b = ArrowGraphHashed
.of([[1, 2], [2, 3]])
.toBuilder()
b.disconnectAll([[1, 2], [3, 4]]) // => true
b.disconnectAll([[3, 4], [5, 6]]) // => false
forEach
Performs given function f for each entry of the collection, using given state as initial traversal state.
forEachf for each entry of the collection, using given state as initial traversal state.Definition
forEach(f: (entry: [N] | WithGraphValues<Tp, N, unknown>['link'], index: number, halt: () => void) => void, options?: {
state?: TraverseState;
}): void;
Parameters
| Name | Type | Description |
|---|---|---|
f | (entry: [N] | WithGraphValues<Tp, N, unknown>['link'], index: number, halt: () => void) => void | the function to perform for each entry, receiving: - entry: the next graph element- index: the index of the element- halt: a function that, if called, ensures that no new elements are passed |
options | {state?: TraverseState;} | object containing the following - state: (optional) the traverse state |
const b = ArrowGraphHashed.of([1], [2, 3], [4]).toBuilder();
b.forEach((entry, i, halt) => {
console.log([entry]);
if (i >= 1) halt();
})
// => logs [1] [2, 3]
O(N)
hasConnection
Returns true if the graph has a connection between given nodes node1 and node2.
hasConnectionnode1 and node2.Definition
hasConnection<UN = N>(node1: RelatedTo<N, UN>, node2: RelatedTo<N, UN>): boolean;
Type parameters
| Name | Default | Description |
|---|---|---|
| UN | N |
Parameters
| Name | Type | Description |
|---|---|---|
node1 | RelatedTo<N, UN> | the first connection node |
node2 | RelatedTo<N, UN> | the second connection node |
const b = ArrowGraphHashed
.of([[1, 2], [2, 3]])
.toBuilder()
b.hasConnection(1, 2) // => true
b.hasConnection(6, 7) // => false
hasNode
Returns true if the graph contains the given node.
hasNodenode.removeNode
Removes the given node, and any of its connections, from the graph.
removeNodenode, and any of its connections, from the graph.removeNodes
Removes the given nodes, and any of their connections, from the graph.
removeNodesnodes, and any of their connections, from the graph.Definition
removeNodes<UN = N>(nodes: StreamSource<RelatedTo<N, UN>>): boolean;
Type parameters
| Name | Default | Description |
|---|---|---|
| UN | N |
Parameters
| Name | Type | Description |
|---|---|---|
nodes | StreamSource<RelatedTo<N, UN>> |
const b = ArrowGraphHashed
.of([[1, 2], [2, 3]])
.toBuilder()
b.removeNodes([1, 6, 7]) // => true
b.removeNodes([6, 7]) // => false