Skip to main content

interface ArrowGraphSorted.NonEmpty<N>

A non-empty type-invariant immutable valued arrow (directed) graph. The connections are internally maintained using sorted collections See the Graph documentation and the ArrowGraphSorted API documentation

Extends: Streamable.NonEmpty<T>, ArrowGraphBase.NonEmpty<N,Tp>, ArrowGraphSorted<N>

Type parameters

NameDescription
Nthe node type

Properties

connectionSize

Returns the amount of connections in the graph.

Definition

readonly connectionSize: number;

example
ArrowGraphHashed.empty<number>().connectionSize  // => 0
ArrowGraphHashed.of([1], [2, 3]).connectionSize // => 1

Overrides

VariantGraphBase.connectionSize

context

Returns the context associated to this collection instance.

Definition

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

Overrides

GraphBase.context

isDirected

Returns true since this is an arrow (directed) graph instance.

Definition

readonly isDirected: true;

Overrides

ArrowGraphBase.isDirectedNonEmpty.isDirected

isEmpty

Returns false since the graph is known to be non-empty.

Definition

readonly isEmpty: false;

example
ArrowGraphHashed.empty<number>().isEmpty  // => true
ArrowGraphHashed.of([1]).isEmpty // => false

Overrides

VariantGraphBase.isEmptyNonEmpty.isEmpty

linkMap

Returns the nested non-empty Map representation of the graph connections.

Definition

readonly linkMap: WithGraphValues<Tp, N, unknown>['linkMapNonEmpty'];

example
ArrowGraphHashed.of([1, 2], [2, 3]).linkMap.toArray()
// => [1 -> HashSet(2), 2 -> HashSet(3)]]

Overrides

GraphBase.linkMapNonEmpty.linkMap

nodeSize

Returns the amount of nodes in the graph.

Definition

readonly nodeSize: number;

example
ArrowGraphHashed.empty<number>().nodeSize  // => 0
ArrowGraphHashed.of([1], [2, 3]).nodeSize // => 3

Overrides

VariantGraphBase.nodeSize

Methods

[Symbol.iterator]

Returns a FastIterator instance used to iterate over the values of this Iterable.

Definition

[Symbol.iterator](): FastIterator<T>;

Overrides

FastIterable.[Symbol.iterator]

addNode

Returns the graph with the given node added, if it was not yet present.

Definition

addNode(node: N): WithGraphValues<Tp, N, V>['nonEmpty'];

Parameters

NameTypeDescription
nodeNthe node to add
example
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

GraphConnect.addNode

addNodes

Returns the non-empty graph with the nodes from the given nodes StreamSource added.

Definition

addNodes(nodes: StreamSource<N>): WithGraphValues<Tp, N, V>['nonEmpty'];

Parameters

NameTypeDescription
nodesStreamSource<N>a StreamSource containing the nodes to add
example
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

GraphConnect.addNodes, GraphConnectNonEmpty.addNodes

asNormal

Returns this collection typed as a 'possibly empty' collection.

Definition

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

example
ArrowGraphHashed.of([1], [2, 3]).asNormal();  // type: ArrowGraphHashed<number>

Overrides

NonEmpty.asNormal

assumeNonEmpty

Returns the collection as a .NonEmpty type

Definition

assumeNonEmpty(): WithGraphValues<Tp, N, V>['nonEmpty'];

throws

RimbuError.EmptyCollectionAssumedNonEmptyError if the collection is empty

example
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()
note

returns reference to this collection

Overrides

VariantGraphBase.assumeNonEmpty

connect

Returns the graph where given nodes node1 and node2 are connected.

Definition

connect(node1: N, node2: N): WithGraphValues<Tp, N, unknown>['nonEmpty'];

Parameters

NameTypeDescription
node1Nthe first node
node2Nthe second node
example
const g = ArrowGraphHashed.of([1, 2], [2, 3])
g.connect(3, 1).stream().toArray()
// => [[1, 2], [2, 3], [3, 1]]

Overrides

GraphBase.connect

connectAll

Returns the non-empty graph with the connections from the given connections StreamSource added.

Definition

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

Parameters

NameTypeDescription
linksStreamSource<WithGraphValues<Tp, N, V>['link']>
example
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

GraphConnect.connectAll, GraphConnectNonEmpty.connectAll

disconnect

Returns the graph with the connection between given node1 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

NameDefaultDescription
UNN

Parameters

NameTypeDescription
node1RelatedTo<N, UN>the first connection node
node2RelatedTo<N, UN>the second connectio node
example
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

VariantGraphBase.disconnect

disconnectAll

Returns the graph with all connections in given links removed if they exist.

Definition

disconnectAll<UN = N>(links: StreamSource<Link<RelatedTo<N, UN>>>): WithGraphValues<Tp, N, V>['normal'];

Type parameters

NameDefaultDescription
UNN

Parameters

NameTypeDescription
linksStreamSource<Link<RelatedTo<N, UN>>>a StreamSource containing tuples of nodes representing connections
example
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

VariantGraphBase.disconnectAll

forEach

Performs given function f 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

NameTypeDescription
f(entry: [N] | WithGraphValues<Tp, N, V>['link'], index: number, halt: () => void) => voidthe 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
example
const g = ArrowGraphHashed.of([1], [2, 3], [4])
g.forEach((entry, i, halt) => {
console.log([entry]);
if (i >= 1) halt();
})
// => logs [1] [2, 3]
note

O(N)

Overrides

VariantGraphBase.forEach

getConnectionsFrom

Returns a Set containing the nodes reachable from given node1 node as keys, and their corresponding values.

Definition

getConnectionsFrom<UN = N>(node1: RelatedTo<N, UN>): WithGraphValues<Tp, N, unknown>['linkConnections'];

Type parameters

NameDefaultDescription
UNN

Parameters

NameTypeDescription
node1RelatedTo<N, UN>the node from which to find the connections
example
const g = ArrowGraphHashed.of([1, 2], [2, 3])
g.getConnectionsFrom(1) // => HashSet(2)
g.getConnectionsFrom(3) // => HashSet()

Overrides

GraphBase.getConnectionsFrom

getConnectionStreamFrom

Returns a Stream containing all the connetions from the given node1

Definition

getConnectionStreamFrom<UN = N>(node1: RelatedTo<N, UN>): Stream<WithGraphValues<Tp, N, V>['link']>;

Type parameters

NameDefaultDescription
UNN

Parameters

NameTypeDescription
node1RelatedTo<N, UN>the first connection node
example
const g = ArrowGraphHashed.of([1], [2, 3])
g.getConnectionStreamFrom(2).toArray() // => [3]
g.getConnectionStreamFrom(5).toArray() // => []

Overrides

VariantGraphBase.getConnectionStreamFrom

getConnectionStreamTo

Returns a Stream containing all the connetions to the given node2

Definition

getConnectionStreamTo<UN = N>(node2: RelatedTo<N, UN>): Stream<WithGraphValues<Tp, N, V>['link']>;

Type parameters

NameDefaultDescription
UNN

Parameters

NameTypeDescription
node2RelatedTo<N, UN>the second connection node
example
const g = ArrowGraphHashed.of([1], [2, 3])
g.getConnectionStreamTo(3).toArray() // => [2]
g.getConnectionStreamTo(5).toArray() // => []

Overrides

VariantGraphBase.getConnectionStreamTo

hasConnection

Returns true if the graph has a connection between given 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 g = ArrowGraphHashed.of([1], [2, 3])
g.hasConnection(2, 3) // => true
g.hasConnection(3, 1) // => false

Overrides

VariantGraphBase.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 g = ArrowGraphHashed.of([1], [2, 3])
g.hasNode(2) // => true
g.hasNode(5) // => false

Overrides

VariantGraphBase.hasNode

isSink

Returns true if the given node has no outgoing connections.

Definition

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

Type parameters

NameDefaultDescription
UNNupper node type used to provide sane typing defaults

Parameters

NameTypeDescription
nodeRelatedTo<N, UN>the node to check
example
const g = ArrowGraphHashed.of([1, 2], [2, 3])
g.isSink(1) // => false
g.isSink(3) // => true

Overrides

ArrowGraphBase.isSink

isSource

Returns true if the given node has no incoming connections.

Definition

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

Type parameters

NameDefaultDescription
UNNupper node type used to provide sane typing defaults

Parameters

NameTypeDescription
nodeRelatedTo<N, UN>the node to check
example
const g = ArrowGraphHashed.of([1, 2], [2, 3])
g.isSource(1) // => true
g.isSource(3) // => false

Overrides

ArrowGraphBase.isSource

nonEmpty

Returns true since this collection is known to be non-empty

Definition

nonEmpty(): true;

example
ArrowGraphHashed.of([1], [2, 3]).nonEmpty()   // => true

Overrides

VariantGraphBase.nonEmpty, NonEmpty.nonEmpty

removeNode

Returns the graph with the given node and all its connections removed.

Definition

removeNode<UN = N>(node: RelatedTo<N, UN>): WithGraphValues<Tp, N, V>['normal'];

Type parameters

NameDefaultDescription
UNN

Parameters

NameTypeDescription
nodeRelatedTo<N, UN>the node to remove
example
const g = ArrowGraphHashed.of([1], [2, 3])
g.removeNode(2).stream().toArray() // => [[1]]
g.removeNode(6).stream().toArray() // => [[1], [2, 3]]

Overrides

VariantGraphBase.removeNode

removeNodes

Returns the graph with all nodes in given nodes stream removed, together with all their connections.

Definition

removeNodes<UN = N>(nodes: StreamSource<RelatedTo<N, UN>>): WithGraphValues<Tp, N, V>['normal'];

Type parameters

NameDefaultDescription
UNN

Parameters

NameTypeDescription
nodesStreamSource<RelatedTo<N, UN>>a StreamSource containing the nodes to remove
example
const g = ArrowGraphHashed.of([1], [2, 3])
g.removeNodes([2, 3]).stream().toArray() // => [[1]]
g.removeNodes([4, 5]).stream().toArray() // => [[1], [2, 3]]

Overrides

VariantGraphBase.removeNodes

removeUnconnectedNodes

Returns the graph with all isolated nodes removed.

Definition

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

example
const g = ArrowGraphHashed.of([1], [2, 3])
g.removeUnconnectedNodes().stream().toArray() // => [[2, 3]]

Overrides

VariantGraphBase.removeUnconnectedNodes

stream

Returns a non-empty Stream containing all entries of this collection as tuples of key and value.

Definition

stream(): Stream.NonEmpty<GraphElement<N>>;

example
ArrowValuedGraphSorted.of([1, 2, 'a'], [2, 3, 'b']).stream().toArray()
// => [[1, 2, 'a'], [2, 3, 'b']]

Overrides

NonEmpty.stream, NonEmpty.stream, VariantGraphBase.stream

streamConnections

Returns a Stream containing all connections of this collection.

Definition

streamConnections(): Stream<WithGraphValues<Tp, N, V>['link']>;

example
ArrowGraphHashed.of([1], [2, 3]).stream().toArray()   // => [[2, 3]]

Overrides

VariantGraphBase.streamConnections

streamNodes

Returns a non-empty Stream containing all nodes of this collection.

Definition

streamNodes(): Stream.NonEmpty<N>;

example
ArrowGraphHashed.of([1], [2, 3]).stream().toArray()   // => [1, 2, 3]

Overrides

VariantGraphBase.streamNodes, NonEmpty.streamNodes

toBuilder

Returns a builder object containing the entries of this collection.

Definition

toBuilder(): WithGraphValues<Tp, N, unknown>['builder'];

example
const builder: ArrowGraphHashed.Builder<number> = ArrowGraphHashed.of([1, 2], [2, 3]).toBuilder()

Overrides

GraphBase.toBuilder

toJSON

Returns a JSON representation of this collection.

Definition

toJSON(): ToJSON<[N, WithGraphValues<Tp, N, V>['linkTarget'][]][]>;

example
ArrowGraphHashed.of([1], [2, 3]).toJSON()
// => { dataType: 'ArrowGraphHashed', value: [[1, []], [2, [3]]] }

Overrides

VariantGraphBase.toJSON

toString

Returns a string representation of this collection.

Definition

toString(): string;

example
ArrowGraphHashed.of([1], [2, 3]).toString()   // => ArrowGraphHashed(1 => [], 2 => [3])

Overrides

VariantGraphBase.toString