Donner SVG main
0.8.0 ยท 766e862a0.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::BloomFilter< kLog2Bits > Class Template Reference

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.

Detailed Description

template<int kLog2Bits>
class donner::BloomFilter< kLog2Bits >

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.

Template Parameters
kLog2BitsBase-2 logarithm of the bit count, 1 to 16.

Member Function Documentation

◆ expectedFalsePositiveRate()

template<int kLog2Bits>
double donner::BloomFilter< kLog2Bits >::expectedFalsePositiveRate ( std::size_t keys)
inlinestaticnoexcept

Approximates the false-positive rate with keys distinct keys inserted.

Parameters
keysNumber of keys inserted.

◆ insert()

template<int kLog2Bits>
void donner::BloomFilter< kLog2Bits >::insert ( BloomHash hash)
inlineconstexprnoexcept

Adds a key.

Parameters
hashThe key's hash.

◆ mayContain()

template<int kLog2Bits>
bool donner::BloomFilter< kLog2Bits >::mayContain ( BloomHash hash) const
inlinenodiscardconstexprnoexcept

Returns false only if hash was not inserted since construction or the last clear.

Parameters
hashThe key's hash.

The documentation for this class was generated from the following file: