UNPKG

@rimbu/graph

Version:

Immutable Graph data structures for TypeScript

51 lines (50 loc) 2.41 kB
import { Stream } from '@rimbu/stream'; import type { VariantGraphBase } from '@rimbu/graph/custom'; import type { LinkType } from './traverse-base.cjs'; /** * 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. * @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 = traverseDepthFirstCustom(g, 1) * console.log(stream.toArray()) * // => [[1, 2], [2, 3], [1, 3], [3, 4]] * ``` */ export declare function traverseDepthFirstCustom<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 depth-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 = traverseDepthFirstHashed(g, 1) * console.log(stream.toArray()) * // => [[1, 2], [2, 3], [1, 3], [3, 4]] * ``` */ export declare function traverseDepthFirstHashed<G extends VariantGraphBase<N, any>, N>(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 depth-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 = traverseDepthFirstSorted(g, 1) * console.log(stream.toArray()) * // => [[1, 2], [2, 3], [1, 3], [3, 4]] * ``` */ export declare function traverseDepthFirstSorted<G extends VariantGraphBase<N, any>, N>(graph: G, startNode: N): Stream<LinkType<G, N>>;