murmur-bloomfilter
It's a Bloom filter, implemented using murmur hash function.
A bloom filter has two methods: add()
and test()
. You
add()
an element 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.
Installation
npm install murmur-bloomfilter --save
Usage:
var BloomFilter = require("murmur-bloomfilter");
var filter = new BloomFilter(1000, 0.01);
filter.add("test")
filter.add("hey");
console.log(filter.test("test"));
console.log(filter.test("man"));
console.log("false positive probability",filter.currentFPP())
console.log(filter.test("hey"));
var filter = new BloomFilter({m:1024,k:2});
filter.add("hey");
console.log(filter.test("hey"));
var filter = new BloomFilter(1000, 0.01);
filter.add("hey");
filter.add("woot");
let buffer=filter.serialize();
var newFilter=new BloomFilter(buffer);
console.log(filter.test("hey"));
var filter = new BloomFilter(1000, 0.01);
filter.add("hey");
filter.add("woot");
let buffer=filter.serialize();
var newFilter=new BloomFilter(buffer);
filter.test('woot');
Implementation
Ported from geeksforgeeks.org tutourial.
- the hashing part is native.
- The hashing function is murmur, because
it's fast and well-tested.
- Buffer is always in its serialized form, makes serializing fast.