@tangle/graph
A module which allows you to build a simple graph, and provides simple helper
methods for modifying an querying that graph.
Example Usage
const Graph = require('@tangle/graph')
const nodes = [
{
key: 'A',
comment: 'What shall we have for dinner?',
previous: null
},
{
key: 'B',
comment: 'Hows about spaghetti?',
previous: ['A']
},
{
key: 'C',
comment: 'My only constraint is no wheat.',
previous: ['A']
},
{
key: 'D',
comment: 'Everyone ok with glutten-free spaghetti?',
previous: ['C', 'D']
}
]
const graph = new Graph (nodes)
graph.isMergeNode('D')
API
new Graph(node, opts) -> graph
Creates a Graph instance which builds a model of the graph.
Notably builds a graph based on links
where:
All of these graph methods assume you're passing in nodes which have :
- a
key
property which is unique - a
thread
property which stores root
(key) and previous
(Array of keys)
In scuttlebutt the keys are the hash addresses of the messages
You can an opts
Object to some methods:
getBacklinks
which takes a node and returns either:
[key]
- an Array of keys of nodes that this node was extending fromnull
- if this was a "root node" (i.e. was the start of a tangle graph)
TODO
this is expected to be used with DAGs (directed acyclic graphs),
but there is currently no internal check built to guarentee this