1.0.2 • Published 9 years ago
@jmalena/bloom-filter v1.0.2
Bloom filter
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.
Installation
To install latest stable version:
npm install @jmalena/bloom-filter --saveExample
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 setAPI
BloomFilter(length, hashCount[, hashFn1[, hashFn2]])
Custom 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.
BloomFilter.add(str)
BloomFilter.containsMaybe(str)
Configuration
Length and number of hash functions can be calculated using this site.
Limitations
Currently works only with length up to 2^32, due to JavaScript integer limitations.