Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hamt-sharding

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hamt-sharding

JavaScript implementation of sharding using hash array mapped tries

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
49K
increased by2.72%
Maintainers
1
Weekly downloads
 
Created
Source

hamt-sharding

standard-readme compliant Jenkins Codecov Dependency Status js-standard-style

JavaScript implementation of hamt for use in sharding

Lead Maintainer

Alex Potsides

Table of Contents

Install

> npm install hamt-sharding

Usage

Example

const hamt = require('hamt-sharding')
const crypto = require('crypto-promise')

// decide how to hash things, can return a Promise
const hashFn = async (value) => {
  return crypto
    .createHash('sha256')
    .update(value)
    .digest()
}

const bucket = hamt({
  hashFn: hashFn
})

await bucket.put('key', 'value')

const output = await bucket.get('key')
// output === 'value'

API

const hamt = require('hamt-sharding')

bucket.put(key, value)

const hamt = require('hamt-sharding')
const bucket = hamt({...})

await bucket.put('key', 'value')

bucket.get(key)

const hamt = require('hamt-sharding')
const bucket = hamt({...})

await bucket.put('key', 'value')

console.info(await bucket.get('key')) // 'value'

bucket.del(key)

const hamt = require('hamt-sharding')
const bucket = hamt({...})

await bucket.put('key', 'value')
await bucket.del('key', 'value')

console.info(await bucket.get('key')) // undefined

bucket.leafCount()

const hamt = require('hamt-sharding')
const bucket = hamt({...})

console.info(bucket.leafCount()) // 0

await bucket.put('key', 'value')

console.info(bucket.leafCount()) // 1

bucket.childrenCount()

const hamt = require('hamt-sharding')
const bucket = hamt({...})

console.info(bucket.childrenCount()) // 0

await bucket.put('key', 'value')

console.info(bucket.childrenCount()) // 234 -- dependent on hashing algorithm

bucket.onlyChild()

bucket.eachLeafSeries()

const hamt = require('hamt-sharding')
const bucket = hamt({...})

await bucket.put('key', 'value')

for await (const child of bucket.eachLeafSeries()) {
  console.info(child.value) // 'value'
}

bucket.serialize(map, reduce)

bucket.asyncTransform(asyncMap, asyncReduce)

bucket.toJSON()

bucket.prettyPrint()

bucket.tableSize()

hamt.isBucket(other)

const hamt = require('hamt-sharding')
const bucket = hamt({...})

console.info(hamt.isBucket(bucket)) // true
console.info(hamt.isBucket(true)) // false

Contribute

Feel free to join in. All welcome. Open an issue!

This repository falls under the IPFS Code of Conduct.

License

MIT

Keywords

FAQs

Package last updated on 23 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc