Name: bloom-filter-js
Owner: DuckDuckGo
Description: Bloom filter written in JS for strings. Tests whether an element belongs to a set. False positive matches are possible, false negatives are not. Also implements Rabin?Karp algorithm with Rabin fingerprint hashes for multiple substring searches.
Forked from: bbondy/bloom-filter-js
Created: 2017-12-18 18:55:57.0
Updated: 2018-05-07 04:31:53.0
Pushed: 2015-12-30 05:11:47.0
Size: 39
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Consider using the native node module equivalent which is faster and better here: https://github.com/bbondy/bloom-filter-cpp
npm install bloom-filter-js
BloomFilter = require('bloom-filter-js');
b = new BloomFilter();
d('Brian');
d('Ronald');
d('Bondy');
rints true
ole.log(b.exists('Brian'));
rints false
ole.log(b.exists('Brian Ronald'));
erialize to a JSON friendly format
json = JSON.stringify(b.toJSON());
reate a new BloomerFilter form a previous serialization
b2 = BloomFilter.from(JSON.parse(json));
ill print the same as b.exists
ole.log(b2.exists('Brian'));
ole.log(b2.exists('Brian Ronald'));
har code arrays can be passed in directly too
t toCharCodeArray = (str) => str.split('').map(c => c.charCodeAt(0));
ill return the same as without converting it to char codes
ole.log(b2.exists(toCharCodeArray('Brian')));
ole.log(b2.exists(toCharCodeArray('Brian Ronald')));
nd you can check if any substring of a passed string exists
eturns true
ole.log(b.substringExists('Hello my name is Brian', 5));
eturns false
ole.log(b.substringExists('Hello my name is Bri', 3));