hamt-sharding
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.1 • Public • Published

    hamt-sharding

    standard-readme compliant Build Status 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 { createHAMT } = require('hamt-sharding')
    const crypto = require('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

    const { createHAMT } = require('hamt-sharding')

    bucket.put(key, value)

    const { createHAMT } = require('hamt-sharding')
    const bucket = createHAMT({...})
    
    await bucket.put('key', 'value')

    bucket.get(key)

    const { createHAMT } = require('hamt-sharding')
    const bucket = createHAMT({...})
    
    await bucket.put('key', 'value')
    
    console.info(await bucket.get('key')) // 'value'

    bucket.del(key)

    const { createHAMT } = require('hamt-sharding')
    const bucket = createHAMT({...})
    
    await bucket.put('key', 'value')
    await bucket.del('key', 'value')
    
    console.info(await bucket.get('key')) // undefined

    bucket.leafCount()

    const { createHAMT } = require('hamt-sharding')
    const bucket = createHAMT({...})
    
    console.info(bucket.leafCount()) // 0
    
    await bucket.put('key', 'value')
    
    console.info(bucket.leafCount()) // 1

    bucket.childrenCount()

    const { createHAMT } = require('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()

    const { createHAMT } = require('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

    MIT

    Install

    npm i hamt-sharding

    DownloadsWeekly Downloads

    16,226

    Version

    2.0.1

    License

    MIT

    Unpacked Size

    463 kB

    Total Files

    36

    Last publish

    Collaborators

    • achingbrain