$ open source · GPL-3.0 — need a commercial license? imqueue.com →

Graph.walk() method

Walks depth first from one vertex.

Signature:

walk(vertex: T, callback?: GraphForeachCallback<T>, visited?: Map<T, boolean>): Graph<T>;

Parameters

Parameter

Type

Description

vertex

T

Vertex to start from.

callback

GraphForeachCallback<T>

(Optional) Called once per vertex reached; returning false prunes.

visited

Map<T, boolean>

(Optional) Vertices already reached. A fresh map by default.

Returns:

Graph<T>

This graph, for chaining.

Remarks

Follows edges as far as they go, marking each vertex as it arrives and never arriving twice, which is what makes it safe on a cyclic graph. Passing a visited map of your own both continues an earlier walk and lets you exclude vertices by marking them before starting.