duckduckgo/bloom-filter-js

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

Homepage:

Size: 39

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status js-standard-style

Consider using the native node module equivalent which is faster and better here: https://github.com/bbondy/bloom-filter-cpp

bloom-filter-js

Installation
npm install bloom-filter-js
Usage
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));

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.