@rimbu/graph
Version:
Immutable Graph data structures for TypeScript
51 lines (50 loc) • 2.43 kB
text/typescript
import { Stream } from '@rimbu/stream';
import type { LinkType } from './traverse-base.mjs';
import type { VariantGraphBase } from '@rimbu/graph/custom';
/**
* 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.
* @param graph - the graph to traverse
* @param startNode - the start node within the graph
* @param addVisitedNode - a function taking the currenty traversed node,
* and returning true if the node has been traversed before, or false otherwise
* @example
* ```ts
* 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]]
* ```
*/
export declare function traverseBreadthFirstCustom<G extends VariantGraphBase<N, any>, N>(graph: G, startNode: N, addVisitedNode?: (node: N) => boolean): Stream<LinkType<G, N>>;
/**
* 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.
* @param graph - the graph to traverse
* @param startNode - the start node within the graph
* @example
* ```ts
* 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]]
* ```
*/
export declare function traverseBreadthFirstHashed<G extends VariantGraphBase<N, V>, N, V>(graph: G, startNode: N): Stream<LinkType<G, N>>;
/**
* 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.
* @param graph - the graph to traverse
* @param startNode - the start node within the graph
* @example
* ```ts
* 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]]
* ```
*/
export declare function traverseBreadthFirstSorted<G extends VariantGraphBase<N, any>, N>(graph: G, startNode: N): Stream<LinkType<G, N>>;