@tangle/graph
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -68,6 +68,8 @@ const isRoot = require('./lib/is-root') | ||
if (this.connected[key]) return this.connected[key] | ||
else if (this.disconnected[key] === undefined) { | ||
else if (this.disconnected[key]) { | ||
console.warn(`key ${key} not in graph`) | ||
return null | ||
} else { | ||
console.warn(`key ${key} found, but is disconnected from main graph`) | ||
return undefined | ||
} | ||
@@ -74,0 +76,0 @@ } |
{ | ||
"name": "@tangle/graph", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "a helper for building + updating traverseable tangle graphs", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -47,3 +47,3 @@ # @tangle/graph | ||
### `new Graph(node, opts) -> graph` | ||
### `new Graph(nodes, opts) -> graph` | ||
@@ -65,6 +65,53 @@ Creates a Graph instance which builds a model of the graph. | ||
## TODO | ||
### `graph.getNode(key) => result` | ||
where `result` is: | ||
- `node` if it's _connected_ within the graph | ||
- `null` if it's _disconnected_ | ||
- `undefined` if it was not in the set of nodes passed in initially | ||
### `graph.isConnected(key) => Boolean` | ||
### `graph.getLinks(key) => [key]` | ||
Returns an Array of keys of nodes that are causally linked to this node-key. | ||
These links pointing _forwards_ in time to node _after_ this key-node in the graph. | ||
### `graph.getBacklinks(key) => [key]` | ||
Returns an Array of keys of nodes that are causally linked to this node-key. | ||
These links pointing _backwards_ in time to node _before_ this key-node in the graph. | ||
### `graph.isBrancNode(key) => Boolean` | ||
Tells you whether the graph diverges as you proceed from the given node-key. | ||
(basically `graph.getLinks(key).length > 1`) | ||
### `graph.isMergeNode(key) => Boolean` | ||
Tells you if 2 or more branches converge in the given node-key. | ||
(basically `graph.getBacklinks(key).length > 1`) | ||
### `graph.isHeadNode(key) => Boolean` | ||
Tells you whether the given node-key belongs to a _head_ of the graph, | ||
i.e. a leading tip causally | ||
(basically `graph.getLinks(key).length === 0`) | ||
### `graph.rootNodeKeys` | ||
A getter which gives you access to an Array of keys for nodes which are "roots" | ||
within the graph (i.e. are the starting points of the graph) | ||
### `graph.raw` | ||
A getter which gives you access to `{ linkMap, backlinkMap }`. | ||
These are data structures which map the links of the graph in both directions. | ||
--- | ||
## NOTES | ||
this is expected to be used with DAGs (directed acyclic graphs), | ||
but there is currently no internal check built to guarentee this | ||
@@ -53,4 +53,4 @@ const test = require('tape') | ||
t.equal(graph.getNode('A'), A, 'getNode') | ||
t.equal(graph.getNode('X'), undefined, 'disconnected node not returned') | ||
t.equal(graph.getNode('Y'), undefined, 'unrelated node not returned') | ||
t.equal(graph.getNode('W'), null, 'disconnected node not returned') | ||
t.equal(graph.getNode('X'), null, 'disconnected node not returned') | ||
t.equal(graph.getNode('Z'), undefined, 'exterior node not return') | ||
@@ -64,3 +64,3 @@ | ||
t.deepEqual(graph.getLinks('W'), [], 'no links for disconnected') | ||
t.deepEqual(graph.getLinks('Y'), [], 'no links for unrelated') | ||
t.deepEqual(graph.getLinks('X'), [], 'no links for disconnected') | ||
t.deepEqual(graph.getLinks('Z'), [], 'no links for exterior') | ||
@@ -74,4 +74,4 @@ | ||
t.deepEqual(graph.getBacklinks('B'), ['A'], 'getBacklinks') | ||
t.deepEqual(graph.getBacklinks('W'), [], 'no backlinks for disconnected') | ||
t.deepEqual(graph.getBacklinks('X'), [], 'no backlinks for disconnected') | ||
t.deepEqual(graph.getBacklinks('Y'), [], 'no backlinks for unrelated') | ||
t.deepEqual(graph.getBacklinks('Z'), [], 'no backlinks for exterior') | ||
@@ -87,4 +87,4 @@ | ||
t.equal(graph.isBranchNode('D'), false, 'D not branchNode') | ||
t.equal(graph.isBranchNode('X'), false, 'X not branchNode') // unrelated node | ||
t.equal(graph.isBranchNode('Y'), false, 'Y is not a branch node') // disconnected node | ||
t.equal(graph.isBranchNode('W'), false, 'W not branchNode') // disconnected node | ||
t.equal(graph.isBranchNode('X'), false, 'X is not a branch node') // disconnected node | ||
t.equal(graph.isBranchNode('Z'), false, 'Z is not a branch node') // exterior node | ||
@@ -99,3 +99,3 @@ | ||
t.equal(graph.isMergeNode('D'), true, 'D is a merge node') | ||
t.equal(graph.isMergeNode('X'), false, 'X not merge node') // unrelated node | ||
t.equal(graph.isMergeNode('X'), false, 'X not merge node') // disconnected | ||
t.equal(graph.isMergeNode('Y'), false, 'Y not merge node') // disconnected node | ||
@@ -111,4 +111,4 @@ t.equal(graph.isMergeNode('Z'), false, 'Z not merge node') // exterior node | ||
t.equal(graph.isHeadNode('D'), true, 'D is headNode') | ||
t.equal(graph.isHeadNode('X'), false, 'X not headNode') // unrelated node | ||
t.equal(graph.isHeadNode('Y'), false, 'Y not headNode') // disconnected node | ||
t.equal(graph.isHeadNode('W'), false, 'W not headNode') // disconnected | ||
t.equal(graph.isHeadNode('X'), false, 'X not headNode') // disconnected | ||
t.equal(graph.isHeadNode('Z'), false, 'Z not headNode') // exterior node | ||
@@ -115,0 +115,0 @@ |
@@ -30,3 +30,3 @@ const test = require('tape') | ||
t.deepEqual(lookup.getNode('A'), A, 'getNode') | ||
t.equal(lookup.getNode('K'), undefined, 'getNode (disconnected key)') | ||
t.equal(lookup.getNode('K'), null, 'getNode (disconnected key)') | ||
t.equal(lookup.getNode('Y'), undefined, 'getNode (invalid key)') | ||
@@ -33,0 +33,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
23059
607
116