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

overview-js-bloom-filter

v0.0.3

Published

Bloom filter for Buffers, optimized for crazy speed.

Downloads

5

Readme

Bloom filter implemented in C++

It's a Bloom filter, implemented in C++ for your JavaScript pleasure.

Quick refresher: a bloom filter has two methods: add() and test(). You add() an element (a utf-8 string, in this case) and voodoo happens; you test() for an element and it returns false if the element is definitely not in the set, or true if the element is probably in the set.

With the right parameters, you can tweak "probably" to be pretty darned probable.

Usage

First, npm install overview-js-bloom-filter.

Now:

var filter = new BloomFilter({ m: 1234567, k: 3 });

// Add some Strings
filter.add('foo'); // UCS-2 / UTF16-LE String: 6 bytes long
filter.add(new Buffer('bar', 'utf-8')); // UTF-8 String: 3 bytes long

// Test for things: Strings...
console.log(filter.test('foo')); // true
console.log(filter.test('baz')); // false
console.log(filter.test('bar')); // false: 'bar' is UTF-16

// A Buffer...
console.log(filter.test(new Buffer('bar', 'utf-8'))); // true

// And even a _piece_ of a Buffer, to avoid a `slice()` object allocation
console.log(filter.test(new Buffer('xxxbarxxx', 'utf-8'), 3, 6); // true

// And of course, you can save it to disk
var buf = filter.serialize(); // a Buffer
var restoredFilter = BloomFilter.load(buf); // a BloomFilter

Confused about what m and k should be? Try http://hur.st/bloomfilter, which plugs numbers into the formulae.

Implementation details

It's a basic bloom filter. It's built to be fast, so:

  • The hashing function is Farmhash, because it's fast and well-tested.
  • It's in C++ because Farmhash is in C++.
  • We hash the string as 64-bit, then treat the result as two independent 32-bit hashes. All but the first two hashes are derived from the first two. Two is enough.
  • We handle Buffers because they let you write fast JavaScript.

LICENSE

AGPL-3.0. This project is (c) Overview Services Inc. Please contact us should you desire a more permissive license.