marcelklehr / toposort

Topologically sort directed acyclic graphs (such as dependency lists) in javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Throws "cyclic dependency" error where there is none

alexlawrence opened this issue · comments

Again if I am not mistaken the following is a bug.

If a depdends on b & c and b also depends on c this is perfectly fine. However the following call results in an error:

toposort([['a', 'b'], ['a', 'c'], ['b', 'c']]);

In my package toposort-class, the following code gives you the desired output:

var Toposort = require("toposort-class"),
    t = new Toposort();


t.add("a", ["b", "c"]);
t.add("b", "c");

// Actually you may want to call .reverse()
console.log(t.sort());

In the latest version of my package toposort, the above bug is fixed ;)

@gustavohenke: nice API, btw