Skip to content

mcrowe/minibloom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minibloom

Extremely fast pure-javascript Bloom filter for node and browsers, with no dependencies.

This library is optimized for smaller strings (< 20 characters). It uses the FNV hash which seems to be the best hashing function for smaller strings. If you are adding large documents, consider using a library that uses the xxhash or murmur hashing algorithms.

This is based on the excellent work by Jason Davies in his bloomfilter.js library. I've made some performance tweaks and done some major modernization of the codebase and added some useful features.

Some references:

Usage

npm install @mcrowe/minibloom --save

import * as Bloom from 'minibloom'

// Create an optimal filter given number of items and error rate.
const filter = Bloom.optimalFilter(1000, 0.01)

// Create a filter using number of bits and hashes
const filter = Bloom.filter(1024, 7)

// Add an item
filter.add('abc')

/**
 * Test for the presence of an item. If false then the item was definitely
 * not added. Otherwise, it *might* have been added (depending on the
 * filter's error rate.)
 */
filter.test('abc')

// Saving and loading from/to base64 strings.
const string = Bloom.toBase64(filter)
const loadedBuffer = Bloom.fromBase64(string)

// Saving and loading from/to buffers (node.js only).
const buffer = Bloom.toBuffer(filter)
const loadedBuffer = Bloom.fromBuffer(buffer)

Development

Install npm modules:

npm install

Run tests:

npm test

Release

Release a new version:

bin/release.sh

This will publish a new version to npm, as well as push a new tag up to github.

About

Extremely fast pure-javascript bloom filter for node and browsers

Resources

License

Stars

Watchers

Forks

Packages

No packages published