3 #include "bloom_filter_math.h"
5 namespace cachemere::policy::detail {
7 template<
typename ItemHash>
9 : m_cardinality{cardinality},
10 m_filter{optimal_filter_size(cardinality),
false},
11 m_nb_hashes{optimal_nb_of_hash_functions(cardinality, m_filter.size())}
19 for (
size_t i = 0; i < m_nb_hashes; ++i) {
20 const size_t filter_idx = mixer();
21 assert(filter_idx < m_filter.size());
23 m_filter.set(filter_idx);
36 for (
size_t i = 0; i < m_nb_hashes; ++i) {
37 const size_t filter_idx = mixer();
38 assert(filter_idx < m_filter.size());
40 if (!m_filter.test(filter_idx)) {
50 return m_filter.num_blocks() *
sizeof(BitsetBlock) +
sizeof(m_nb_hashes);
55 assert(m_filter.size() > 0);
56 return static_cast<double>(m_filter.count()) /
static_cast<double>(m_filter.size());