hypercore-dag
DAGs on top of hypercore, allowing verified random-access to graph nodes
Last updated 4 years ago by emilbay .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install hypercore-dag 
SYNC missed versions from official npm registry.

hypercore-dag

DAGs on top of hypercore, allowing verified random-access to graph nodes

Usage

'use strict'

var assert = require('assert')

var hypercore = require('hypercore')
var memdb = require('memdb')
var hypercoreDag = require('.')

var core = hypercore(memdb())
var dag = hypercoreDag(core.createFeed())

// We're building the following graph (Time on x axis, depth on y axis)
// 0     2
// \- 1  \
//    \--\-- 3

dag.add(null, 'Root', function (err, ref0) {
  assert.ifError(err)

  dag.add(ref0, 'Child 1', function (err, ref1) {
    assert.ifError(err)

    dag.add(null, 'Another root', function (err, ref2) {
      assert.ifError(err)

      dag.add([ref0, ref1, ref2], 'Tie them', function (err, ref3) {
        assert.ifError(err)

        dag.get(ref3, function (err, node) {
          assert.ifError(err)

          assert.deepEqual(node.links, [0, 1, 2])
          assert.equal(node.depth, 2)
          assert.equal(node.value, 'Tie them')
        })
      })
    })
  })
})

API

hypercoreDag(feed, [opts])

opts being {lock: mutexify()}

dag.add(links, value, [callback])

dag.get(index, callback)

dag.createReadStream([opts])

Extras

require('hypercore-dag/bfs-stream')(startIndex, [opts])

Preform a Breadth-first search from startIndex

require('hypercore-dag/dfs-stream')(startIndex, [opts])

Preform a Depth-first search from startIndex

Install

npm install hypercore-dag

License

ISC

Current Tags

  • 0.0.0                                ...           latest (4 years ago)

1 Versions

  • 0.0.0                                ...           4 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 1
Dependencies (16)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |