How to use iamap - 3 common examples

To help you get started, we’ve selected a few iamap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rvagg / js-ipld-hashmap / ipld-hashmap.js View on Github external
throw new TypeError('HashMap.create() requires a \'hasher\' function and a \'hashBytes\' integer to use a custom \'hashAlg\'')
  }
  IAMap.registerHasher(hashAlg, hashBytes, hasher)

  const bitWidth = fromOptions('bitWidth', 'number', DEFAULT_BITWIDTH)
  const bucketSize = fromOptions('bucketSize', 'number', DEFAULT_BUCKET_SIZE)

  const iamapOptions = { hashAlg, bitWidth, bucketSize }

  let iamap
  if (CID.isCID(root)) {
    // load existing, ignoring bitWidth & bucketSize, they are loaded from the existing root
    iamap = await IAMap.load(store, root)
  } else {
    // create new
    iamap = await IAMap.create(store, iamapOptions)
  }

  return new HashMap(iamap)
}
github rvagg / js-ipld-hashmap / ipld-hashmap.js View on Github external
const hasher = fromOptions('hasher', 'function', DEFAULT_HASHER)
  const hashBytes = fromOptions('hashBytes', 'number', DEFAULT_HASH_BYTES)
  if (hashAlg !== DEFAULT_HASH_ALGORITHM && (typeof options.hasher !== 'function' || options.hashBytes !== 'number')) {
    throw new TypeError('HashMap.create() requires a \'hasher\' function and a \'hashBytes\' integer to use a custom \'hashAlg\'')
  }
  IAMap.registerHasher(hashAlg, hashBytes, hasher)

  const bitWidth = fromOptions('bitWidth', 'number', DEFAULT_BITWIDTH)
  const bucketSize = fromOptions('bucketSize', 'number', DEFAULT_BUCKET_SIZE)

  const iamapOptions = { hashAlg, bitWidth, bucketSize }

  let iamap
  if (CID.isCID(root)) {
    // load existing, ignoring bitWidth & bucketSize, they are loaded from the existing root
    iamap = await IAMap.load(store, root)
  } else {
    // create new
    iamap = await IAMap.create(store, iamapOptions)
  }

  return new HashMap(iamap)
}
github rvagg / js-ipld-hashmap / ipld-hashmap.js View on Github external
isEqual (cid1, cid2) {
      return cid1.equals(cid2)
    },

    isLink (obj) {
      return CID.isCID(obj)
    }
  }

  const hashAlg = fromOptions('hashAlg', 'string', DEFAULT_HASH_ALGORITHM)
  const hasher = fromOptions('hasher', 'function', DEFAULT_HASHER)
  const hashBytes = fromOptions('hashBytes', 'number', DEFAULT_HASH_BYTES)
  if (hashAlg !== DEFAULT_HASH_ALGORITHM && (typeof options.hasher !== 'function' || options.hashBytes !== 'number')) {
    throw new TypeError('HashMap.create() requires a \'hasher\' function and a \'hashBytes\' integer to use a custom \'hashAlg\'')
  }
  IAMap.registerHasher(hashAlg, hashBytes, hasher)

  const bitWidth = fromOptions('bitWidth', 'number', DEFAULT_BITWIDTH)
  const bucketSize = fromOptions('bucketSize', 'number', DEFAULT_BUCKET_SIZE)

  const iamapOptions = { hashAlg, bitWidth, bucketSize }

  let iamap
  if (CID.isCID(root)) {
    // load existing, ignoring bitWidth & bucketSize, they are loaded from the existing root
    iamap = await IAMap.load(store, root)
  } else {
    // create new
    iamap = await IAMap.create(store, iamapOptions)
  }

  return new HashMap(iamap)

iamap

An **I**mmutable **A**synchronous **Map**.

Apache-2.0
Latest version published 12 months ago

Package Health Score

53 / 100
Full package analysis