interface VariantGraphBase<N,V,Tp>
undocumented
Companion namespace: VariantGraphBase
Extends: FastIterable<T>
Implemented by: VariantValuedGraphBase<N,V,Tp>, VariantGraphBase.NonEmpty<N,V,Tp>, GraphBase<N,Tp>, GraphConnect<N,V,Tp>
Type parameters
| Name | Constraints | Default | Description |
|---|---|---|---|
| N | undocumented | ||
| V | undocumented | ||
| Tp | VariantGraphBase.Types | VariantGraphBase.Types | undocumented |
Properties
connectionSize
Returns the amount of connections in the graph.
connectionSizeDefinition
readonly connectionSize: number;
ArrowGraphHashed.empty<number>().connectionSize // => 0
ArrowGraphHashed.of([1], [2, 3]).connectionSize // => 1
isDirected
Returns true if the graph is an arrow (directed) graph.
isDirectedDefinition
readonly isDirected: boolean;
isEmpty
Returns true if the graph has no nodes.
isEmptyDefinition
readonly isEmpty: boolean;
ArrowGraphHashed.empty<number>().isEmpty // => true
ArrowGraphHashed.of([1]).isEmpty // => false
nodeSize
Returns the amount of nodes in the graph.
nodeSizeDefinition
readonly nodeSize: number;
ArrowGraphHashed.empty<number>().nodeSize // => 0
ArrowGraphHashed.of([1], [2, 3]).nodeSize // => 3
Methods
[Symbol.iterator]
Returns a FastIterator instance used to iterate over the values of this Iterable.
[Symbol.iterator]FastIterator instance used to iterate over the values of this Iterable.assumeNonEmpty
Returns the collection as a .NonEmpty type
assumeNonEmptyDefinition
assumeNonEmpty(): WithGraphValues<Tp, N, V>['nonEmpty'];
RimbuError.EmptyCollectionAssumedNonEmptyError if the collection is empty
ArrowGraphHashed.empty<number>().assumeNonEmpty() // => throws
const g: ArrowGraphHashed<number> = ArrowGraphHashed.of([1, 1], [2, 2])
const g2: ArrowGraphHashed.NonEmpty<number> = g // => compiler error
const g3: ArrowGraphHashed.NonEmpty<number> = g.assumeNonEmpty()
returns reference to this collection
disconnect
Returns the graph with the connection between given node1 and node2 removed if it exists.
disconnectnode1 and node2 removed if it exists.Definition
disconnect<UN = N>(node1: RelatedTo<N, UN>, node2: RelatedTo<N, UN>): WithGraphValues<Tp, N, V>['normal'];
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 connectio node |
const g = ArrowGraphHashed.of([1], [2, 3])
g.disconnect(2, 3).stream().toArray() // => [[1], [2], [3]]
g.disconnect(1, 2).stream().toArray() // => [[1], [2, 3]]
disconnectAll
Returns the graph with all connections in given links removed if they exist.
disconnectAlllinks removed if they exist.Definition
disconnectAll<UN = N>(links: StreamSource<Link<RelatedTo<N, UN>>>): WithGraphValues<Tp, N, V>['normal'];
Type parameters
| Name | Default | Description |
|---|---|---|
| UN | N |
Parameters
| Name | Type | Description |
|---|---|---|
links | StreamSource<Link<RelatedTo<N, UN>>> | a StreamSource containing tuples of nodes representing connections |
const g = ArrowGraphHashed.of([1], [2, 3])
g.disconnectAll([[1, 2], [3, 4]]).stream().toArray() // => [[1], [2, 3]]
g.disconnectAll([[2, 3], [3, 4]]).stream().toArray() // => [[1], [2], [3]]
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, V>['link'], index: number, halt: () => void) => void, options?: {
state?: TraverseState;
}): void;
Parameters
| Name | Type | Description |
|---|---|---|
f | (entry: [N] | WithGraphValues<Tp, N, V>['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 g = ArrowGraphHashed.of([1], [2, 3], [4])
g.forEach((entry, i, halt) => {
console.log([entry]);
if (i >= 1) halt();
})
// => logs [1] [2, 3]
O(N)
getConnectionStreamFrom
Returns a Stream containing all the connetions from the given node1
getConnectionStreamFromStream containing all the connetions from the given node1Definition
getConnectionStreamFrom<UN = N>(node1: RelatedTo<N, UN>): Stream<WithGraphValues<Tp, N, V>['link']>;
Type parameters
| Name | Default | Description |
|---|---|---|
| UN | N |
Parameters
| Name | Type | Description |
|---|---|---|
node1 | RelatedTo<N, UN> | the first connection node |
const g = ArrowGraphHashed.of([1], [2, 3])
g.getConnectionStreamFrom(2).toArray() // => [3]
g.getConnectionStreamFrom(5).toArray() // => []
getConnectionStreamTo
Returns a Stream containing all the connetions to the given node2
getConnectionStreamToStream containing all the connetions to the given node2Definition
getConnectionStreamTo<UN = N>(node2: RelatedTo<N, UN>): Stream<WithGraphValues<Tp, N, V>['link']>;
Type parameters
| Name | Default | Description |
|---|---|---|
| UN | N |
Parameters
| Name | Type | Description |
|---|---|---|
node2 | RelatedTo<N, UN> | the second connection node |
const g = ArrowGraphHashed.of([1], [2, 3])
g.getConnectionStreamTo(3).toArray() // => [2]
g.getConnectionStreamTo(5).toArray() // => []
hasConnection
Returns true if the graph has a connection between given 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 g = ArrowGraphHashed.of([1], [2, 3])
g.hasConnection(2, 3) // => true
g.hasConnection(3, 1) // => false
hasNode
Returns true if the graph contains the given node.
hasNodenode.nonEmpty
Returns true if there is at least one node in the collection, and instructs the compiler to treat the collection as a .NonEmpty type.
nonEmptyDefinition
nonEmpty(): this is WithGraphValues<Tp, N, V>['nonEmpty'];
const g: ArrowGraphHashed<number> = ArrowGraphHashed.of([1, 1], [2, 2])
g.streamNodes().first(0) // compiler allows fallback value since the Stream may be empty
if (g.nonEmpty()) {
g.streamNodes().first(0) // compiler error: fallback value not allowed since Stream is not empty
}
removeNode
Returns the graph with the given node and all its connections removed.
removeNodenode and all its connections removed.Definition
removeNode<UN = N>(node: RelatedTo<N, UN>): WithGraphValues<Tp, N, V>['normal'];
Type parameters
| Name | Default | Description |
|---|---|---|
| UN | N |
Parameters
| Name | Type | Description |
|---|---|---|
node | RelatedTo<N, UN> | the node to remove |
const g = ArrowGraphHashed.of([1], [2, 3])
g.removeNode(2).stream().toArray() // => [[1]]
g.removeNode(6).stream().toArray() // => [[1], [2, 3]]
removeNodes
Returns the graph with all nodes in given nodes stream removed, together with all their connections.
removeNodesnodes stream removed, together with all their connections.Definition
removeNodes<UN = N>(nodes: StreamSource<RelatedTo<N, UN>>): WithGraphValues<Tp, N, V>['normal'];
Type parameters
| Name | Default | Description |
|---|---|---|
| UN | N |
Parameters
| Name | Type | Description |
|---|---|---|
nodes | StreamSource<RelatedTo<N, UN>> | a StreamSource containing the nodes to remove |
const g = ArrowGraphHashed.of([1], [2, 3])
g.removeNodes([2, 3]).stream().toArray() // => [[1]]
g.removeNodes([4, 5]).stream().toArray() // => [[1], [2, 3]]
removeUnconnectedNodes
Returns the graph with all isolated nodes removed.
removeUnconnectedNodesDefinition
removeUnconnectedNodes(): WithGraphValues<Tp, N, V>['normal'];
const g = ArrowGraphHashed.of([1], [2, 3])
g.removeUnconnectedNodes().stream().toArray() // => [[2, 3]]
stream
Returns a Stream containing all graph elements of this collection as single tuples for isolated nodes and 2-valued tuples of nodes for connections.
streamStream containing all graph elements of this collection as single tuples for isolated nodes and 2-valued tuples of nodes for connections.Definition
stream(): Stream<[N] | WithGraphValues<Tp, N, V>['link']>;
ArrowGraphHashed.of([1], [2, 3]).stream().toArray() // => [[1], [2, 3]]
streamConnections
Returns a Stream containing all connections of this collection.
streamConnectionsStream containing all connections of this collection.Definition
streamConnections(): Stream<WithGraphValues<Tp, N, V>['link']>;
ArrowGraphHashed.of([1], [2, 3]).stream().toArray() // => [[2, 3]]
streamNodes
Returns a Stream containing all nodes of this collection.
streamNodesStream containing all nodes of this collection.toJSON
Returns a JSON representation of this collection.
toJSONDefinition
toJSON(): ToJSON<[N, WithGraphValues<Tp, N, V>['linkTarget'][]][]>;
ArrowGraphHashed.of([1], [2, 3]).toJSON()
// => { dataType: 'ArrowGraphHashed', value: [[1, []], [2, [3]]] }