Cachemere
Modular Caching Library for C++
|
1 #ifndef CACHEMERE_COUNTINGBLOOMFILTER_H
2 #define CACHEMERE_COUNTINGBLOOMFILTER_H
7 #include <absl/hash/hash.h>
9 #include "hash_mixer.h"
11 namespace cachemere::policy::detail {
33 template<
typename ItemKey>
void add(
const ItemKey& item);
51 template<
typename ItemKey> [[nodiscard]] uint32_t
estimate(
const ItemKey& item)
const;
55 [[nodiscard]] uint32_t
cardinality()
const noexcept;
67 [[nodiscard]]
double saturation()
const noexcept;
70 uint32_t m_cardinality;
71 std::vector<uint32_t> m_filter;
73 uint32_t m_nb_nonzero = 0;
78 #include "counting_bloom_filter.hpp"
void add(const ItemKey &item)
Increment the count for a given item by one.
Definition: counting_bloom_filter.hpp:17
Space-efficient probabilistic data structure to estimate the number of times an item was inserted in ...
Definition: counting_bloom_filter.h:18
size_t memory_used() const noexcept
Get an estimate of the memory consumption of the filter.
Definition: counting_bloom_filter.hpp:86
void clear()
Clear the filter while keeping the allocated memory.
Definition: counting_bloom_filter.hpp:48
void decay()
Divide counter values by two.
Definition: counting_bloom_filter.hpp:54
double saturation() const noexcept
Get the saturation of the filter.
Definition: counting_bloom_filter.hpp:96
uint32_t estimate(const ItemKey &item) const
Get the counter estimate for a given item.
Definition: counting_bloom_filter.hpp:64
uint32_t cardinality() const noexcept
Get the cardinality of the filter.
Definition: counting_bloom_filter.hpp:81
CountingBloomFilter(uint32_t cardinality)
Constructor.
Definition: counting_bloom_filter.hpp:10