Tiny graph data structure for Client or Server
const graph = require('tiny-graph'),
g = graph();
g.setNodeValue('f', 3);
g.setNodeValue('h', 21);
g.add('f', 'h');
g.setEdgeValue('f', 'h', 100);
console.log(g.adjacent('f', 'h')); // true
console.log(g.neighbors('f')); // ['h']
console.log(g.getEdgeValue('f', 'h')); // 100
tiny-graph can be installed from npm & bower, and supports AMD loaders or script tags (window.graph
).
Adds the edge from x
to y
, if it is not there
Tests whether there is an edge from node x
to node y
Removes the edge from x
to y
, if it is there
Removes node x
from the graph, if it is there
Deserializes arg as the graph
Returns the value associated to the edge (x
, y
)
Returns the value associated with the node x
Lists all nodes y
such that there is an edge from x
to y
Sets the value associated to the edge (x
, y
) to v
Sets the value associated with the node x
to v
Serializes the graph as JSON
Copyright (c) 2018 Jason Mulligan Licensed under the BSD-3 license