npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ibf

v5.0.1

Published

invertible bloom filter using typed arrays

Downloads

4

Readme

Invertible Bloom Filter as described by Eppstein et al. in What's the Difference? Efficient Set Reconciliation without Prior Context.

Implemented with typed arrays. No external dependencies. standard style.

The example in this README is run as the package's test suite.

Configuration

Initialization

var IBF = require('ibf')
var assert = require('assert')
var xxh = require('xxhashjs').h32

var cellCount = 100

var seeds = [0x0000, 0xAAAA, 0xFFFF]

var options = {
  cellCount: cellCount,

  checkHash: function (idBuffer) {
    var digest = xxh(idBuffer, 0x1234)
    var digestBuffer = new ArrayBuffer(4)
    new Uint32Array(digestBuffer)[0] = digest
    return digestBuffer
  },

  keyHashes: seeds.map(function (seed) {
    return function (id) {
      return xxh(id, seed) % cellCount
    }
  }),

  // Keys will be SHA-2 digests of 8 * 32 = 256 bits.
  idSumOctets: 32,

  // Internal hashes will be 32-bit murmur digests.
  hashSumOctets: 4
}

var filter = new IBF(options)

assert.deepStrictEqual(filter.arrayBuffer.byteLength, 4000)

assert.throws(function () {
  IBF({})
})

Inserting, Removing, and Querying

var crypto = require('crypto')

var keys = {}
;['a', 'b', 'c', 'd'].forEach(function (example) {
  keys[example] = crypto.createHash('sha256')
    .update('this is ' + example)
    .digest()
    .buffer // Keys are ArrayBuffers.
})

filter.insert(keys.a)
assert(filter.has(keys.a), 'has A')
assert(filter.additional(keys.a), 'A is additional')
assert(!filter.missing(keys.a), 'A is not missing')

assert(!filter.has(keys.b), 'does not have B')
assert(!filter.additional(keys.b), 'B is not additional')
assert(!filter.missing(keys.b), 'B is not missing')

filter.insert(keys.c)
assert(filter.has(keys.c), 'has C')

filter.remove(keys.c)
assert(!filter.has(keys.c), 'no longer has C')

Cloning

var clone = filter.clone()

clone.remove(keys.d)

assert(clone.has(keys.a), 'clone has A')
assert(clone.missing(keys.d), 'clone missing D')

Subtraction and Decoding

var hasABC = IBF(options)
hasABC.insert(keys.a)
hasABC.insert(keys.b)
hasABC.insert(keys.c)

var hasCD = IBF(options)
hasCD.insert(keys.c)
hasCD.insert(keys.d)

var difference = hasABC.clone()
difference.subtract(hasCD)

var decoded = difference.decode()

assert(decoded !== false)

assert.deepStrictEqual(decoded.additional.length, 2)

function toHex (x) { return Buffer.from(x).toString('hex') }

assert(decoded.additional.some(function (element) {
  return toHex(element) === toHex(keys.a)
}), 'additional A')

assert(decoded.additional.some(function (element) {
  return toHex(element) === toHex(keys.b)
}), 'additional B')

assert.deepStrictEqual(decoded.missing.length, 1)

assert(decoded.missing.some(function (element) {
  return toHex(element) === toHex(keys.d)
}), 'missing D')