mhelvens / graph.js

a javascript library for storing arbitrary data in mathematical (di)graphs, as well as traversing and analyzing them in various ways (ECMAScript 6 Ready)
MIT License
92 stars 14 forks source link

Other traversal algorithms #13

Open dominicbarnes opened 8 years ago

dominicbarnes commented 8 years ago

Do any of the methods here accomplish either a depth-first or breadth-first traversal directly? It doesn't seem like that is the case, although there are clearly other algorithms sprinkled in.

If they are not included, is it because they are not difficult to implement by hand?

dominicbarnes commented 8 years ago

Just searching around, I've come to discover a lot more tree traversal algorithms.

I suppose issue is similar to (if not an outright duplicated of) #8. Do you think this library will expose some sort of "plugin" infrastructure to add different algorithms? Or are you thinking that these libraries are standalone?

var Graph = require('graph.js');
var DFT = require('depth-first-traversal');

var graph = new Graph();

// standalone
DFT(graph, function (key, value) {
  // visit vertex
});

// plugin
graph.use(DFT);
graph.walk('depth-first', function (key, value) {
  // visit vertex
});
mhelvens commented 8 years ago

Probably both.

DFT(graph, () => { ... });
Graph.plugin(DFT);
graph.DFT(() => { ... });