Comparing version 0.0.1 to 0.0.2
28
graph.js
@@ -177,22 +177,22 @@ // graph.js | ||
GraphJS.prototype.isForest = function () { | ||
var isForest = true; | ||
var hasMultipleParents = false; | ||
var numberOflinksToNodes = {}; | ||
_.each(this.referenceDictionary, function (node) { | ||
if(!node.discovered) { | ||
depthFirstSearch( | ||
node, | ||
function () { return false; }, | ||
function () { | ||
isForest = false; | ||
} | ||
); | ||
} | ||
_.each(node.links, function (link) { | ||
if(!numberOflinksToNodes[link.ref.id]) { | ||
numberOflinksToNodes[link.ref.id] = 0; | ||
} | ||
numberOflinksToNodes[link.ref.id] += 1; | ||
}); | ||
}); | ||
// cleanup | ||
_.each(this.referenceDictionary, function (node) { | ||
delete node.discovered; | ||
_.each(numberOflinksToNodes, function (count) { | ||
if(count > 1) { | ||
hasMultipleParents = true; | ||
} | ||
}); | ||
return isForest; | ||
return !hasMultipleParents && !this.hasCycles(); | ||
}; | ||
@@ -199,0 +199,0 @@ |
{ | ||
"name": "mathgraph", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "graph utilities", | ||
@@ -5,0 +5,0 @@ "main": "graph.js", |
@@ -152,2 +152,7 @@ var GraphJS = require('./graph'); | ||
test.strictEqual(new GraphJS([ | ||
{ id: 1, data: 'a' }, | ||
{ id: 2, data: 'b', link: 1 } | ||
]).isForest(), true, 'mixed up order (in response to a bug)'); | ||
test.done(); | ||
@@ -154,0 +159,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13568
343