A counting Bloom filter of 2^kLog2Slots 8-bit saturating counters with two probes per key, which supports remove. More...
#include "donner/base/BloomFilter.h"
Public Member Functions | |
| constexpr | CountingBloomFilter () noexcept=default |
| Creates an empty filter. | |
| constexpr bool | insert (BloomHash hash) noexcept |
| Adds one occurrence of a key. | |
| constexpr void | remove (BloomHash hash) noexcept |
| Removes one occurrence of a key. | |
| constexpr bool | mayContain (BloomHash hash) const noexcept |
Returns false only if hash has no occurrence left since construction or the last clear. | |
| constexpr void | clear () noexcept |
| Removes every key and resets saturated counters. | |
Static Public Member Functions | |
| static double | expectedFalsePositiveRate (std::size_t keys) noexcept |
Approximates the false-positive rate with keys distinct keys present, assuming no counters remain saturated after removals. | |
Static Public Attributes | |
| static constexpr std::size_t | kSlots = Probes::kSlots |
| Number of counters. | |
| static constexpr std::uint8_t | kSaturated = 255 |
| Counter value that is never decremented. | |
A counting Bloom filter of 2^kLog2Slots 8-bit saturating counters with two probes per key, which supports remove.
Invariant: after any sequence of operations in which every remove(h) follows a matching insert(h), mayContain(h) is true for every h inserted more times than removed. A counter that reaches 255 stays at 255: insert does not wrap it and remove never decrements it, so removal cannot create a false negative, at the cost of a false positive on that counter until clear. Sizing guidance matches BloomFilter, counting the keys present: with 4,096 counters (kLog2Slots = 12, 4 KiB), 100 keys give about 0.23 percent false positives.
Storage is inline (2^kLog2Slots bytes) 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.
| kLog2Slots | Base-2 logarithm of the counter count, 1 to 16. |
|
inlinestaticnoexcept |
Approximates the false-positive rate with keys distinct keys present, assuming no counters remain saturated after removals.
| keys | Number of keys present. |
|
inlineconstexprnoexcept |
Adds one occurrence of a key.
| hash | The key's hash. |
|
inlinenodiscardconstexprnoexcept |
Returns false only if hash has no occurrence left since construction or the last clear.
| hash | The key's hash. |
|
inlineconstexprnoexcept |
Removes one occurrence of a key.
The key must have been inserted more times than removed since construction or the last clear. Removing a key without a matching insertion can cause false negatives for other keys.
| hash | The key's hash. |