Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/rimbu/graph/main/traverse/index.ts>traverseDepthFirstSorted

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
function traverseDepthFirstSorted
import { traverseDepthFirstSorted } from "https://deno.land/x/rimbu@0.13.5/graph/main/traverse/index.ts";

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.

Examples

Example 1

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]]

Type Parameters

G extends VariantGraphBase<N, any>
N

Parameters

graph: G
  • the graph to traverse
startNode: N
  • the start node within the graph

Returns

Stream<LinkType<G, N>>