Skip to main content

namespace Traverse

undocumented

Functions

traverseBreadthFirstCustom

Returns a stream of connections that can be reached in the given graph starting at the given startNode, and using breadth-first traversal. It can avoid loops if needed in a custom way by supplying the addVisitedNode function.

Definition

export declare function traverseBreadthFirstCustom<G extends VariantGraphBase<N, any>, N>(graph: G, startNode: N, addVisitedNode?: (node: N) => boolean): Stream<LinkType<G, N>>;

Type parameters
NameDescription
G
N

Parameters

NameTypeDescription
graphGthe graph to traverse
startNodeNthe start node within the graph
addVisitedNode(node: N) => booleana function taking the currenty traversed node, and returning true if the node has been traversed before, or false otherwise
example
const g = EdgeGraphHashed.of([1, 2], [2, 3], [1, 3], [3, 4])
const stream = traverseBreadthFirstCustom(g, 1)
console.log(stream.toArray())
// => [[1, 2], [1, 3], [2, 3], [3, 4]]

traverseBreadthFirstHashed

Returns a stream of connections that can be reached in the given graph starting at the given startNode, and using breadth-first traversal. It avoids loops by internally placing the visited nodes in a HashSet builder.

Definition

export declare function traverseBreadthFirstHashed<G extends VariantGraphBase<N, V>, N, V>(graph: G, startNode: N): Stream<LinkType<G, N>>;

Type parameters
NameDescription
G
N
V

Parameters

NameTypeDescription
graphGthe graph to traverse
startNodeNthe start node within the graph
example
const g = EdgeGraphHashed.of([1, 2], [2, 3], [1, 3], [3, 4])
const stream = traverseBreadthFirstHashed(g, 1)
console.log(stream.toArray())
// => [[1, 2], [1, 3], [2, 3], [3, 4]]

traverseBreadthFirstSorted

Returns a stream of connections that can be reached in the given graph starting at the given startNode, and using breadth-first traversal. It avoids loops by internally placing the visited nodes in a SortedSet builder.

Definition

export declare function traverseBreadthFirstSorted<G extends VariantGraphBase<N, any>, N>(graph: G, startNode: N): Stream<LinkType<G, N>>;

Type parameters
NameDescription
G
N

Parameters

NameTypeDescription
graphGthe graph to traverse
startNodeNthe start node within the graph
example
const g = EdgeGraphHashed.of([1, 2], [2, 3], [1, 3], [3, 4])
const stream = traverseBreadthFirstSorted(g, 1)
console.log(stream.toArray())
// => [[1, 2], [1, 3], [2, 3], [3, 4]]

traverseDepthFirstCustom

Returns a stream of connections that can be reached in the given graph starting at the given startNode, and using depth-first traversal. It can avoid loops if needed in a custom way by supplying the addVisitedNode function.

Definition

export declare function traverseDepthFirstCustom<G extends VariantGraphBase<N, any>, N>(graph: G, startNode: N, addVisitedNode?: (node: N) => boolean): Stream<LinkType<G, N>>;

Type parameters
NameDescription
G
N

Parameters

NameTypeDescription
graphGthe graph to traverse
startNodeNthe start node within the graph
addVisitedNode(node: N) => booleana function taking the currenty traversed node, and returning true if the node has been traversed before, or false otherwise
example
const g = EdgeGraphHashed.of([1, 2], [2, 3], [1, 3], [3, 4])
const stream = traverseDepthFirstCustom(g, 1)
console.log(stream.toArray())
// => [[1, 2], [2, 3], [1, 3], [3, 4]]

traverseDepthFirstHashed

Returns a stream of connections that can be reached in the given graph starting at the given startNode, and using depth-first traversal. It avoids loops by internally placing the visited nodes in a HashSet builder.

Definition

export declare function traverseDepthFirstHashed<G extends VariantGraphBase<N, any>, N>(graph: G, startNode: N): Stream<LinkType<G, N>>;

Type parameters
NameDescription
G
N

Parameters

NameTypeDescription
graphGthe graph to traverse
startNodeNthe start node within the graph
example
const g = EdgeGraphHashed.of([1, 2], [2, 3], [1, 3], [3, 4])
const stream = traverseDepthFirstHashed(g, 1)
console.log(stream.toArray())
// => [[1, 2], [2, 3], [1, 3], [3, 4]]

traverseDepthFirstSorted

Returns a stream of connections that can be reached in the given graph starting at the given startNode, and using depth-first traversal. It avoids loops by internally placing the visited nodes in a SortedSet builder.

Definition

export declare function traverseDepthFirstSorted<G extends VariantGraphBase<N, any>, N>(graph: G, startNode: N): Stream<LinkType<G, N>>;

Type parameters
NameDescription
G
N

Parameters

NameTypeDescription
graphGthe graph to traverse
startNodeNthe start node within the graph
example
const g = EdgeGraphHashed.of([1, 2], [2, 3], [1, 3], [3, 4])
const stream = traverseDepthFirstSorted(g, 1)
console.log(stream.toArray())
// => [[1, 2], [2, 3], [1, 3], [3, 4]]