Skip to main content
Module

x/rimbu/mod.ts>Traverse.traverseBreadthFirstSorted

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

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.

Examples

Example 1

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

Parameters

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