66#ifndef COMPACT_QUOTIENT_FILTER_H
67#define COMPACT_QUOTIENT_FILTER_H
113 return (1ULL <<
r_) - 1;
160 void set_occ(
const size_t i,
const bool v)
noexcept
165 void set_cont(
const size_t i,
const bool v)
noexcept
170 void set_shft(
const size_t i,
const bool v)
noexcept
179 for (
size_t b = 0; b <
r_; ++b)
188 for (
size_t b = 0; b <
r_; ++b)
260 const size_t prev =
decr(empty);
367 ah_domain_error_if(
q +
r > 64) <<
"Compact_Quotient_Filter: q + r must be <= 64 (got " <<
static_cast<int>(
q +
r)
388 <<
"Compact_Quotient_Filter::from_capacity: fp_rate must be in (0, 1) (got " <<
fp_rate <<
")";
392 const auto r_d = std::max(1.0, std::ceil(-std::log2(
fp_rate)));
394 int q_v =
static_cast<int>(
q_d);
395 int r_v =
static_cast<int>(
r_d);
398 <<
"Compact_Quotient_Filter::from_capacity: requested fp_rate requires r = " <<
r_v
399 <<
" remainder bits, which is outside the supported range [1, 60]";
405 <<
"Compact_Quotient_Filter::from_capacity: requested (expected_n, fp_rate) leads to q = " <<
q_v
406 <<
", which is outside the supported range [1, 32]";
421 <<
"Compact_Quotient_Filter::insert: filter is full (" <<
num_elems_ <<
"/" <<
num_slots_ <<
")";
533 return std::ldexp(1.0, -
static_cast<int>(
r_));
575 }
while (
other.get_cont(s));
584 const double slots =
static_cast<double>(n) / 0.75;
585 auto qv =
static_cast<uint8_t>(std::max(1.0, std::ceil(std::log2(slots))));
586 auto rv =
static_cast<uint8_t>(std::max(1.0, std::ceil(-std::log2(
fp_rate))));
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Space-efficient bit array implementation.
Contiguous array of bits.
int read_bit(const size_t i) const
Read bit i.
void write_bit(const size_t i, const unsigned int value)
Write bit i with the value.
void reserve(const size_t dim)
Reserve memory in advance for the bit array dim dimension.
void swap(BitArray &array) noexcept
Memory-optimized quotient filter with bit-packed slots.
bool is_run_start(const size_t i) const noexcept
size_t find_run_start(const size_t fq) const noexcept
void set_occ(const size_t i, const bool v) noexcept
bool get_occ(const size_t i) const noexcept
size_t bits_per_slot() const noexcept
double load_factor() const noexcept
Current load factor.
size_t find_first_unused(const size_t start) const noexcept
void set_cont(const size_t i, const bool v) noexcept
size_t memory_usage() const noexcept
Memory usage in bytes.
void swap(Compact_Quotient_Filter &other) noexcept
Swap in O(1).
uint32_t seed() const noexcept
Hash seed.
Compact_Quotient_Filter(uint8_t q, uint8_t r, uint32_t seed=0x5F3759DF)
Construct a compact quotient filter.
void clear_element(const size_t i) noexcept
static std::pair< uint8_t, uint8_t > estimate(size_t n, double fp_rate)
Estimate (q, r) for n elements and target FP rate.
uint8_t q() const noexcept
Quotient bits.
size_t capacity() const noexcept
Number of slots (2^q).
void shift_elements_left(const size_t pos) noexcept
void set_bit_at(const size_t slot, const size_t bit_idx, const bool v) noexcept
static Compact_Quotient_Filter from_capacity(size_t expected_n, double fp_rate, uint32_t seed=0x5F3759DF)
Construct from desired capacity and false positive rate.
bool slot_empty(const size_t i) const noexcept
bool is_empty() const noexcept
True if empty.
size_t decr(const size_t i) const noexcept
uint64_t rem_mask() const noexcept
size_t incr(const size_t i) const noexcept
void clear() noexcept
Remove all elements.
Compact_Quotient_Filter & insert(const T &item)
Insert an element.
bool get_cont(const size_t i) const noexcept
size_t size() const noexcept
Number of elements.
bool get_bit_at(const size_t slot, const size_t bit_idx) const noexcept
void merge(const Compact_Quotient_Filter &other)
Merge another filter (same q, r, seed).
bool remove(const T &item) noexcept
Remove an element.
void set_shft(const size_t i, const bool v) noexcept
uint8_t r() const noexcept
Remainder bits.
std::pair< size_t, uint64_t > fingerprint(const T &item) const
size_t slot_offset(const size_t i) const noexcept
void shift_elements_right(const size_t pos, size_t empty) noexcept
bool do_insert(const size_t fq, const uint64_t fr)
bool contains(const T &item) const noexcept
Test membership.
void set_rem(const size_t i, const uint64_t rem) noexcept
uint64_t get_rem(const size_t i) const noexcept
void set_element(const size_t i, const bool cont, const bool shft, const uint64_t rem) noexcept
bool get_shft(const size_t i) const noexcept
bool has_element(const size_t i) const noexcept
double false_positive_rate() const noexcept
Theoretical FP probability ~ 2^{-r}.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
std::decay_t< typename HeadC::Item_Type > T
size_t murmur3hash(const Key &key, std::uint32_t seed)