ngraph.graph
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -306,3 +306,6 @@ /** | ||
fromNode.links.push(link); | ||
toNode.links.push(link); | ||
if (fromId !== toId) { | ||
// make sure we are not duplicating links for self-loops | ||
toNode.links.push(link); | ||
} | ||
@@ -309,0 +312,0 @@ recordLinkChange(link, 'add'); |
{ | ||
"name": "ngraph.graph", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Base graph structure in ngraph.*", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -40,3 +40,14 @@ ngraph.graph | ||
``` js | ||
g.addNode('world', 'custom data'); // Now node 'world' is associated with a string object 'custom data' | ||
// Node 'world' is associated with a string object 'custom data' | ||
g.addNode('world', 'custom data'); | ||
// You can associate arbitrary objects with node: | ||
g.addNode('server', { | ||
status: 'on', | ||
ip: '127.0.0.1' | ||
}); | ||
// to get data back use `data` property of node: | ||
var server = g.getNode('server'); | ||
console.log(server.data); // prints associated object | ||
``` | ||
@@ -43,0 +54,0 @@ |
@@ -22,2 +22,15 @@ var test = require('tap').test, | ||
test('forEachLinkedNode handles self-loops', function(t) { | ||
t.plan(1); | ||
var graph = createGraph(); | ||
graph.addLink(1, 1); | ||
// we should visit exactly one time | ||
graph.forEachLinkedNode(1, function(node, link) { | ||
t.ok(link.fromId === 1 && link.toId === 1, 'Link 1 is visited once'); | ||
}); | ||
t.end(); | ||
}); | ||
test('forEachLinkedNode will not crash on invalid node id', function(t) { | ||
@@ -24,0 +37,0 @@ t.plan(0); |
Sorry, the diff of this file is not supported yet
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
30464
701
162