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

node_bloom_filter

v1.0.4

Published

The most sophisticated bloom filter for Node, supports counting bloom Filters, deletions and serializations. The counters are handled to take care of the overflows and dynamically expand the underlying ArrayBuffer when expansion is needed.

Downloads

12

Readme

Node Bloom filter

Node bloom filter is a sophisticated Bloom filter available for NodeJs which can be optionally transformed to a counting bloom filter and can thus perform delete operations as well.

  • Supports deletions
  • Can yield a desired false positive rate(probability) when given the total number of elements in the sets
  • Supports an optimisation flag to calculate the number of hashes and bits to use internally
  • Serialization to an Arraybuffer, which can be converted to JSON/UTF-8/base64 and is left to the user :)
  • Dynamically resizes the underlying Arraybuffer to handle the counter overflows when used as a counting bloom filter.
  • Implements double hashing technique to generate multiple hashes using murmur3
  • Uses bit manipulations to optimise on memory usage
  • When implemented as a counting bloom filter, it can support 4,8,16,32 bits per counters to handle overflows
  • Extends Events to notify when the underlying Arraybuffer is resized

Getting Started

To install: npm install node_bloom_filter

Usage

Bloom Filter

To create a general implementation, pass the following in the constructor:

let bFilter = new bloomFilter({
    nHash:10,
    nBits:1024*8
});

If no options are passed, the filter created by default can support 569 members with a false rate of upto 0.001

To create the optimized implementation, pass an object in the constructor:

let bFilter = new bloomFilter({
    optimize: true,/*This automatically calculates number of hashes and bits to be used internally*/
    falsePositiveRate: 0.001,/*Desired false positive rate,less rate will use more memory internally*/
    isCounting: false,// False by default,
    nElements:10000
});

To create a counting bloom Filter that supports deletions as well, just pass

let bFilter = new bloomFilter({
    optimize: true,/*This automatically calculates number of hashes and bits to be used internally*/
    falsePositiveRate: 0.001,/*Desired false positive rate,less rate will use more memory internally*/
    isCounting: true,// False by default,
    nElements:10000
});

Add an element

bFilter.add('hello world');

Test for membership

if(bFilter.has('hello world')===true){
    console.log('Present, but may be a false positive');
}else{
    console.log('Not present definitely');
}

Delete

This is available only for couting bloom filters

bFilter.delete('hello world');

Serialization and Deserialization

let bFilterArrayBuffer=bFilter.serialize();
let newFilter=new bloomFilter({},bFilterArrayBuffer);
newFilter.add('hello, i am the best bloom filter');

On resize

bFilter.on('resized',(bitsPerCounter)=>{
    console.log('bits per counter',bitsPerCounter);
});

Test

To test: npm run test

Acknowledgements

  • Hat tip to anyone who uses and contributes to the code....
  • Purav Aggarwal :)