hamt-sharding
JavaScript implementation of sharding using hash array mapped tries
Table of contents
Install
$ npm i hamt-sharding
Usage
Example
import { createHAMT } from 'hamt-sharding'
import crypto from 'crypto-promise'
const hashFn = async (buf) => {
return crypto
.createHash('sha256')
.update(buf)
.digest()
}
const bucket = createHAMT({
hashFn: hashFn
})
await bucket.put('key', 'value')
const output = await bucket.get('key')
API
import { createHAMT } from 'hamt-sharding'
bucket.put(key, value)
import { createHAMT } from 'hamt-sharding'
const bucket = createHAMT({...})
await bucket.put('key', 'value')
bucket.get(key)
import { createHAMT } from 'hamt-sharding'
const bucket = createHAMT({...})
await bucket.put('key', 'value')
console.info(await bucket.get('key'))
bucket.del(key)
import { createHAMT } from 'hamt-sharding'
const bucket = createHAMT({...})
await bucket.put('key', 'value')
await bucket.del('key', 'value')
console.info(await bucket.get('key'))
bucket.leafCount()
import { createHAMT } from 'hamt-sharding'
const bucket = createHAMT({...})
console.info(bucket.leafCount())
await bucket.put('key', 'value')
console.info(bucket.leafCount())
bucket.childrenCount()
import { createHAMT } from 'hamt-sharding'
const bucket = createHAMT({...})
console.info(bucket.childrenCount())
await bucket.put('key', 'value')
console.info(bucket.childrenCount())
bucket.onlyChild()
bucket.eachLeafSeries()
import { createHAMT } from 'hamt-sharding'
const bucket = createHAMT({...})
await bucket.put('key', 'value')
for await (const child of bucket.eachLeafSeries()) {
console.info(child.value)
}
bucket.serialize(map, reduce)
bucket.asyncTransform(asyncMap, asyncReduce)
bucket.toJSON()
bucket.prettyPrint()
bucket.tableSize()
Contribute
Feel free to join in. All welcome. Open an issue!
This repository falls under the IPFS Code of Conduct.
License
Licensed under either of
Contribute
Feel free to join in. All welcome. Open an issue!
This repository falls under the IPFS Code of Conduct.