interface EdgeValuedGraphBase.NonEmpty<N,V,Tp>
undocumented
Extends: Streamable.NonEmpty<T>, EdgeValuedGraphBase<N,V,Tp>, ValuedGraphBase.NonEmpty<N,V,Tp>
Type parameters
| Name | Constraints | Default | Description |
|---|---|---|---|
| N | undocumented | ||
| V | undocumented | ||
| Tp | EdgeValuedGraphBase.Types | EdgeValuedGraphBase.Types | undocumented |
Properties
connectionSize
Returns the amount of connections in the graph.
connectionSizecontext
Returns the context associated to this collection instance.
contextcontext associated to this collection instance.isDirected
Returns false since this is an edge (undirected) graph instance.
isDirectedisEmpty
Returns false since the graph is known to be non-empty.
isEmptylinkMap
Returns the nested non-empty Map representation of the graph connections.
linkMapDefinition
readonly linkMap: WithGraphValues<Tp, N, V>['linkMapNonEmpty'];
ArrowValuedGraphHashed.of([1, 2, 'a'], [2, 3, 'b']).linkMap.toArray()
// => [[1, HashMap(2 -> 'a')], [2, HashMap(3 -> 'b')]]
Overrides
nodeSize
Returns the amount of nodes in the graph.
nodeSizeMethods
[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.addNode
Returns the graph with the given node added, if it was not yet present.
addNodenode added, if it was not yet present.Definition
addNode(node: N): WithGraphValues<Tp, N, V>['nonEmpty'];
Parameters
| Name | Type | Description |
|---|---|---|
node | N | the node to add |
const g = ArrowGraphHashed.of([1], [2, 3])
g.addNode(4).stream().toArray() // => [[1], [2, 3], [4]]
g.addNode(1).stream().toArray() // ==> [[1], [2, 3]]
Overrides
addNodes
Returns the non-empty graph with the nodes from the given nodes StreamSource added.
addNodesnodes StreamSource added.Definition
addNodes(nodes: StreamSource<N>): WithGraphValues<Tp, N, V>['nonEmpty'];
Parameters
| Name | Type | Description |
|---|---|---|
nodes | StreamSource<N> | a StreamSource containing the nodes to add |
const g = ArrowGraphHashed.of([1], [2, 3])
g.addNodes([4, 1]).stream().toArray() // => [[1], [2, 3], [4]]
g.addNodes([1, 2]).stream().toArray() // => [[1], [2, 3]]
Overrides
asNormal
Returns this collection typed as a 'possibly empty' collection.
asNormalDefinition
asNormal(): WithGraphValues<Tp, N, V>['normal'];
ArrowGraphHashed.of([1], [2, 3]).asNormal(); // type: ArrowGraphHashed<number>
Overrides
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
Overrides
connect
Returns the graph where given nodes node1 and node2 are connected with the given value.
connectnode1 and node2 are connected with the given value.Definition
connect(node1: N, node2: N, value: V): WithGraphValues<Tp, N, V>['nonEmpty'];
Parameters
| Name | Type | Description |
|---|---|---|
node1 | N | the first node |
node2 | N | the second node |
value | V | the connection value |
const g = ArrowValuedGraphHashed.of([1, 2, 'a'], [2, 3, 'b'])
g.connect(3, 1, 'c').stream().toArray()
// => [[1, 2, 'a'], [2, 3, 'b'], [3, 1, 'c']]
Overrides
connectAll
Returns the non-empty graph with the connections from the given connections StreamSource added.
connectAllconnections StreamSource added.Definition
connectAll(links: StreamSource<WithGraphValues<Tp, N, V>['link']>): WithGraphValues<Tp, N, V>['nonEmpty'];
Parameters
| Name | Type | Description |
|---|---|---|
links | StreamSource<WithGraphValues<Tp, N, V>['link']> |
const g = ArrowGraphHashed.of([1], [2, 3])
g.connectAll([[1, 2], [3, 1]]).stream().toArray() // => [[1, 2], [2, 3], [3, 1]]
const g2 = ArrowValuedGraphHashed.of([1], [2, 3, 'a'])
g2.connectAll([[1, 2, 'b'], [2, 3, 'c']]).stream().toArray()
// => [[1, 2, 'b'], [2, 3, 'c']]
Overrides
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]]
Overrides
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]]
Overrides
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)
Overrides
getConnectionsFrom
Returns a Map containing the nodes and connection values reachable from given node1 node as keys, and their corresponding values.
getConnectionsFromnode1 node as keys, and their corresponding values.Definition
getConnectionsFrom<UN = N>(node1: RelatedTo<N, UN>): WithGraphValues<Tp, N, V>['linkConnections'];
Type parameters
| Name | Default | Description |
|---|---|---|
| UN | N |
Parameters
| Name | Type | Description |
|---|---|---|
node1 | RelatedTo<N, UN> | the node from which to find the connections |
const g = ArrowValuedGraphHashed.of([1, 2, 'a'], [2, 3, 'b'])
g.getConnectionsFrom(1) // => HashMap(2 -> 'a')
g.getConnectionsFrom(3) // => HashMap()
Overrides
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() // => []
Overrides
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() // => []
Overrides
getValue
Returns the value of the connection between given node1 and node2
getValuenode1 and node2Definitions
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
| 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 = ArrowValuedGraphHashed.of([1, 2, 'a'], [2, 3, 'b'])
g.getValue(1, 2) // => 'a'
g.getValue(3, 4) // => undefined
g.getValue(1, 2, 'z') // => 'a'
g.getValue(3, 4, 'z') // => 'z'
Overrides
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
Overrides
hasNode
Returns true if the graph contains the given node.
hasNodenode.mapValues
Returns a non-empty graph with the same connections, but where the given mapFun function is applied to each connection value.
mapValuesmapFun function is applied to each connection value.Definition
mapValues<V2>(mapFun: (value: V, node1: N, node2: N) => V2): WithGraphValues<Tp, N, V2>['nonEmpty'];
Type parameters
| Name | Description |
|---|---|
| V2 |
Parameters
| Name | Type | Description |
|---|---|---|
mapFun | (value: V, node1: N, node2: N) => V2 | a function taking a value and connection's node1 and node2, and returning a new value |
ArrowValuedGraphHashed.of([1, 2, 'a'], [2, 3, 'bc']).mapValues(v => v.length).toArray()
// => [[1, 2, 1], [2, 3, 2]]
Overrides
modifyAt
Returns the graph with the connection between given node1 and node2 modified according to given options.
modifyAtnode1 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)| V;
}): WithGraphValues<Tp, N, V>['normal'];
Parameters
| Name | Type | Description |
|---|---|---|
node1 | N | the first connection node |
node2 | N | the second connection node |
options | {ifNew?: OptLazyOr<V, Token>;ifExists?: ((value: V, remove: Token) => V |Token)| V;} | an object containing the following information: - ifNew: (optional) if the given connection is not present in the collection, this value or function will be used to generate a new connection. If a function returning the token argument is given, no new entry is created. - ifExists: (optional) if a value is associated with given connection, this function is called with the given value to return a new value. As a second argument, a remove token is given. If the function returns this token, the current connection is removed. |
const g = ArrowValuedGraphHashed.of([1, 2, 'a'], [2, 3, 'b'])
g.modifyAt(3, 4, { ifNew: 'c' }).toArray()
// => [[1, 2, 'a'], [2, 3, 'b'], [3, 4, 'c']]
g.modifyAt(3, 4, { ifNew: (none) => 1 < 2 ? none : 'c' }).toArray()
// => [[1, 2, 'a'], [2, 3, 'b']]
g.modifyAt(1, 2, { ifExists: () => 'c' }).toArray()
// => [[1, 2, 'c'], [2, 3, 'b']]
g.modifyAt(1, 2, { ifExists: (v) => v + 'z' }).toArray()
// => [[1, 2, 'az'], [2, 3, 'b']]
g.modifyAt(2, 3, { ifExists: (v, remove) => v === 'a' ? v : remove }).toArray()
// => [[1, 2, 'a']]
Overrides
nonEmpty
Returns true since this collection is known to be non-empty
nonEmptyDefinition
nonEmpty(): this is WithGraphValues<Tp, N, V>['nonEmpty'];
ArrowGraphHashed.of([1], [2, 3]).nonEmpty() // => true
Overrides
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]]
Overrides
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]]
Overrides
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]]
Overrides
stream
Returns a non-empty Stream containing all entries of this collection as tuples of key and value.
streamDefinition
stream(): Stream.NonEmpty<ValuedGraphElement<N, V>>;
EdgeValuedGraphHashed.of([1, 2, 'a'], [2, 3, 'b']).stream().toArray()
// => [[1, 2, 'a'], [2, 3, 'b']]
Overrides
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]]
Overrides
streamNodes
Returns a non-empty Stream containing all nodes of this collection.
streamNodesStream containing all nodes of this collection.Definition
streamNodes(): Stream.NonEmpty<N>;
ArrowGraphHashed.of([1], [2, 3]).stream().toArray() // => [1, 2, 3]
Overrides
toBuilder
Returns a builder object containing the entries of this collection.
toBuilderDefinition
toBuilder(): WithGraphValues<Tp, N, V>['builder'];
const builder: ArrowValuedGraphHashed.Builder<number, string> = ArrowValuedGraphHashed.of([1, 2, 'a'], [2, 3, 'b']).toBuilder()
Overrides
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]]] }