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

x/rimbu/core/mod.ts>Traverse.traverseDepthFirstCustom

Rimbu is a TypeScript library focused on immutable, performant, and type-safe collections and other tools.
Go to Latest
function Traverse.traverseDepthFirstCustom
import { Traverse } from "https://deno.land/x/rimbu@0.13.1/core/mod.ts";
const { traverseDepthFirstCustom } = Traverse;

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.

Examples

Example 1

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

Parameters

graph: G
  • the graph to traverse
startNode: N
  • the start node within the graph
optional
addVisitedNode: (node: N) => boolean = [UNSUPPORTED]
  • a function taking the currenty traversed node, and returning true if the node has been traversed before, or false otherwise