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

strata-estimator

v2.0.0

Published

strata set difference estimator

Downloads

4

Readme

Invertible Bloom Filter-based strata set difference estimator as described by Eppstein et al. in What's the Difference? Efficient Set Reconciliation without Prior Context.

Depends only on ibf.

standard style.

var StrataEstimator = require('strata-estimator')

// This code in this `README` is runs as a test suite.
var assert = require('assert')

// A non-cryptographic hash function.
var xxh = require('xxhashjs').h32

// The number of cells per invertible bloom filter.
var cellCount = 80

// Seeds for the three distinct bloom filter hash functions.
var seeds = [0x0000, 0x9999, 0xFFFF]

var options = {
  // The hash to use to assign keys to strata.
  hash: function (input) { return xxh(input, 0xAAAA) },

  // The number of strata.
  strataCount: 32,

  // Options for each stratum's invertible bloom filter, passed to
  // the ibf package constructor.
  // See https://www.npmjs.com/package/ibf
  filters: {
    cellCount: cellCount,
    checkHash: function binaryXXH (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
      }
    }),
    idSumOctets: 32,
    hashSumOctets: 4
  }
}

// Create some test keys.

var keys = []
for (var i = 0; i < 100; i++) {
  keys.push(
    require('crypto').createHash('sha256')
    .update(Number(i).toString(36))
    .digest()
    .buffer
  )
}

var has100 = new StrataEstimator(options)
keys.slice(0, 100).forEach(function (key) { has100.insert(key) })

// With or without `new`

var has25 = StrataEstimator(options)
keys.slice(0, 25).forEach(function (key) { has25.insert(key) })

var has50 = new StrataEstimator(options)
keys.slice(0, 50).forEach(function (key) { has50.insert(key) })

var has75 = StrataEstimator(options)
keys.slice(0, 75).forEach(function (key) { has75.insert(key) })

var cloneHas25 = has25.clone()

// Throws an error for bad options

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

assert.equal(has100.decode(has100), 0)

var diff25 = has100.decode(has75)
assert(diff25 >= 25)
assert(diff25 <= 100)

var diff50 = has100.decode(has50)
assert(diff50 >= 50)
assert(diff50 <= 100)

var diff75 = has100.decode(has25)
assert(diff75 >= 75)
assert(diff75 <= 128)

var diffClone75 = has100.decode(cloneHas25)
assert(diffClone75 >= 75)
assert(diffClone75 <= 128)