Simple and dependency-free Bloom filter implementation.
Bloom filter is a space-efficient data structure, which can test whether an element is not or is probably a member of a set.
To install latest stable version:
npm install @jmalena/bloom-filter --save
import BloomFilter from '@jmalena/bloom-filter'
const filter = new BloomFilter(65536, 2)
filter.add('redrum')
filter.containsMaybe('redrum') // true: "redrum" is probably in a set
filter.containsMaybe('otrozone') // false: "otrozone" is definitely not in a setCustom hash function must take string as input and return unsigned 32-bit integer as output. It's highly recommended to hashFn1 and hashFn2 be different hash functions.
Length and number of hash functions can be calculated using this site.
Currently works only with length up to 2^32, due to JavaScript integer limitations.