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

hamt-sharding

Package Overview
Dependencies
Maintainers
2
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

  • 3.0.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

hamt-sharding

ipfs.tech Discuss codecov CI

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'

// decide how to hash buffers made from keys, can return a 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')
// output === 'value'

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')) // 'value'

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')) // undefined

bucket.leafCount()

import { createHAMT } from 'hamt-sharding'
const bucket = createHAMT({...})

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

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

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

bucket.childrenCount()

import { createHAMT } from 'hamt-sharding'
const bucket = createHAMT({...})

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

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

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

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) // '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

Contributions welcome! Please check out the issues.

Also see our contributing document for more information on how we work, and about contributing in general.

Please be aware that all interactions related to this repo are subject to the IPFS Code of Conduct.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Keywords

FAQs

Package last updated on 06 Feb 2024

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