Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emilbayes/hypercore-dag
DAGs on top of hypercore, allowing verified random-access to graph nodes
https://github.com/emilbayes/hypercore-dag
Last synced: 12 days ago
JSON representation
DAGs on top of hypercore, allowing verified random-access to graph nodes
- Host: GitHub
- URL: https://github.com/emilbayes/hypercore-dag
- Owner: emilbayes
- License: isc
- Created: 2016-10-11T02:21:48.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-10-11T03:37:26.000Z (about 8 years ago)
- Last Synced: 2024-10-17T16:31:43.111Z (22 days ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 24
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-peer-to-peer - hypercore-dag - access to graph nodes (Modules)
- awesome-peer-to-peer - hypercore-dag - access to graph nodes (Modules)
README
# `hypercore-dag`
> DAGs on top of hypercore, allowing verified random-access to graph nodes
## Usage
```js
'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({
sparse: true // Set this to true if you only want to download nodes as you're walking the graph
}))// We're building the following graph (Time on x axis, depth on y axis)
// 0 2
// \- 1 \
// \--\-- 3dag.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](https://en.wikipedia.org/wiki/Breadth-first_search)
from `startIndex`### `require('hypercore-dag/dfs-stream')(startIndex, [opts])`
Preform a [Depth-first search](https://en.wikipedia.org/wiki/Depth-first_search)
from `startIndex`## Install
```sh
npm install hypercore-dag
```## License
[ISC](LICENSE.md)