bloom

A Bloom Filter implementation using Cyclic Polynomial Hash function. It can automatically calculate optimal number of hashes given a target bit size. It can also automatically assign bit size given number of false positives. Bloom Filter base is a bitvector.

Types

BloomFilter[H] = object
  bitVector: BitVector[H]
  numberOfHashes: int
  numberOfBits: int
  numberOfElements: int
  useMurmurHash: bool

Procs

proc newBloomFilter[H](numberOfElements: int; numberOfBits: int;
                      numOfHashes: int = 0; useMurmurHash: bool = true): BloomFilter[H] {...}{.
    inline.}
Creat a new Bloom Filter. If number of hashes provided is zero, we calculate the optimal number of hashes automatically.
proc newBloomFilter[H](numberOfElements: int; falsePositiveRate: float;
                      numOfHashes: int = 0; useMurmurHash: bool = true): BloomFilter[H] {...}{.
    inline.}
Create a new Bloom Filter. If number of hashes provided is zero, we calculate the optimal number of hashes automatically. Using false positive rate provided, we automatically calculate the bit size required to ensure requirement is met.
proc insert[H](bf: var BloomFilter[H]; item: string) {...}{.inline.}
Insert item into Bloom Filter
proc lookup[H](bf: var BloomFilter[H]; item: string): bool {...}{.inline.}
Check if item is in Bloom Filter
proc `$`[H](bf: BloomFilter[H]): string {...}{.inline.}