Graphology Traversal
Miscellaneous traversal functions to be used with graphology
.
Installation
npm install graphology-traversal
Usage
bfs
Perform a BFS (Breadth-First Search) over the given graph using a callback.
import {bfs} from 'graphology-traversal';
import {bfs} from 'graphology-traversal/bfs';
bfs(graph, function(node, attr) {
console.log(node, attr);
});
Arguments
- graph Graph: a graphology instance.
- callback function: iteration callback taking the traversed node and its attributes.
dfs
Perform a DFS (Depth-First Search) over the given graph using a callback.
import {dfs} from 'graphology-traversal';
import {dfs} from 'graphology-traversal/dfs';
dfs(graph, function(node, attr) {
console.log(node, attr);
});
Arguments
- graph Graph: a graphology instance.
- callback function: iteration callback taking the traversed node and its attributes.