Skip to content

Commit

Permalink
Support unmapped adjacency list indices antoinerg#14
Browse files Browse the repository at this point in the history
  • Loading branch information
HusseinElMotayam committed Mar 11, 2020
1 parent deb7762 commit 9fda2c0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion johnson.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module.exports = function findCircuits(edges, cb) {
function subgraph(minId) {
// Remove edges with indice smaller than minId
for(var i = 0; i < edges.length; i++) {
if(i < minId) edges[i] = [];
if(i < minId || !edges[i]) edges[i] = [];
edges[i] = edges[i].filter(function(i) {
return i >= minId;
});
Expand Down
19 changes: 19 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ test('find elementarty circuits in', function(t) {
t.end();
});

t.test('another simple directed graph with orphaned nodes', function(t) {
// V4 V2
// +-<---o---<---o
// | |
// o V0 ^ o V3
// | V1|
// +------>------o
var g = [];
g[0] = [1];
g[1] = [2];
// g[3] is unmapped
g[2] = [4];
g[4] = [0];

var circuits = findCircuits(g);
t.deepEqual(circuits, [[0, 1, 2, 4, 0]]);
t.end();
});

t.test('another simple directed graph with callback', function(t) {
var g = [
[1],
Expand Down

0 comments on commit 9fda2c0

Please sign in to comment.