A Bloom filter of 2^kLog2Bits bits with two probes per key, for sets that only grow until clear. More...
#include "donner/base/BloomFilter.h"
Public Member Functions | |
| constexpr | BloomFilter () noexcept=default |
| Creates an empty filter. | |
| constexpr void | insert (BloomHash hash) noexcept |
| Adds a key. | |
| constexpr bool | mayContain (BloomHash hash) const noexcept |
Returns false only if hash was not inserted since construction or the last clear. | |
| constexpr void | clear () noexcept |
| Removes every key. | |
Static Public Member Functions | |
| static double | expectedFalsePositiveRate (std::size_t keys) noexcept |
Approximates the false-positive rate with keys distinct keys inserted. | |
Static Public Attributes | |
| static constexpr std::size_t | kBits = Probes::kSlots |
| Number of bits. | |
A Bloom filter of 2^kLog2Bits bits with two probes per key, for sets that only grow until clear.
mayContain never returns false for an inserted key; the false-positive rate for absent keys is approximated by expectedFalsePositiveRate. Sizing guidance: with 4,096 bits (kLog2Bits = 12), 100 keys give about 0.23 percent false positives, 500 keys 4.7 percent and 1,000 keys 15 percent.
Storage is inline (2^kLog2Bits / 8 bytes, at least 8) and every operation except clear takes constant time and never allocates. There is no internal synchronization: concurrent mayContain calls are safe while no thread modifies the filter, and any modification needs exclusive access.
| kLog2Bits | Base-2 logarithm of the bit count, 1 to 16. |
|
inlinestaticnoexcept |
Approximates the false-positive rate with keys distinct keys inserted.
| keys | Number of keys inserted. |
|
inlineconstexprnoexcept |
Adds a key.
| hash | The key's hash. |
|
inlinenodiscardconstexprnoexcept |
Returns false only if hash was not inserted since construction or the last clear.
| hash | The key's hash. |