118#ifndef QUOTIENT_FILTER_H
119#define QUOTIENT_FILTER_H
159 return (1ULL <<
r_) - 1;
261 void set_occ(
const size_t i,
const bool v)
noexcept
269 void set_cont(
const size_t i,
const bool v)
noexcept
277 void set_shft(
const size_t i,
const bool v)
noexcept
369 const size_t prev =
decr(empty);
491 ah_domain_error_if(
q +
r > 64) <<
"Quotient_Filter: q + r must be <= 64 (got " <<
static_cast<int>(
q +
r) <<
")";
508 <<
"Quotient_Filter::from_capacity: fp_rate must be in (0, 1) (got " <<
fp_rate <<
")";
647 return std::ldexp(1.0, -
static_cast<int>(
r_));
688 <<
"Quotient_Filter::merge: destination filter is full (" <<
num_elems_ <<
"/" <<
num_slots_ <<
")";
690 }
while (
other.get_cont(s));
699 const double slots =
static_cast<double>(n) / 0.75;
700 auto qv =
static_cast<uint8_t>(std::max(1.0, std::ceil(std::log2(slots))));
701 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_overflow_error()
Throws std::overflow_error unconditionally.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Simple dynamic array with automatic resizing and functional operations.
void swap(Array &s) noexcept
Swap this with s
Quotient filter for probabilistic set membership with deletion.
bool get_occ(size_t i) const noexcept
static constexpr uint64_t CONT_BIT
size_t decr(const size_t i) const noexcept
size_t incr(const size_t i) const noexcept
Quotient_Filter & insert(const T &item)
Insert an element.
static Quotient_Filter from_capacity(size_t expected_n, double fp_rate, uint32_t seed=0x5F3759DF)
Construct from desired capacity and false positive rate.
double load_factor() const noexcept
Current load factor.
bool has_element(const size_t i) const noexcept
size_t memory_usage() const noexcept
Memory usage in bytes.
uint8_t q() const noexcept
Quotient bits.
bool get_shft(size_t i) const noexcept
bool is_empty() const noexcept
True if empty.
void set_rem(const size_t i, const uint64_t rem) noexcept
double false_positive_rate() const noexcept
Theoretical FP probability ~ 2^{-r}.
void set_shft(const size_t i, const bool v) noexcept
Insert_Result do_insert(size_t fq, uint64_t fr)
size_t capacity() const noexcept
Number of slots (2^q).
uint8_t r() const noexcept
Remainder bits.
uint64_t get_rem(const size_t i) const noexcept
void set_occ(const size_t i, const bool v) noexcept
void merge(const Quotient_Filter &other)
Merge another filter (same q, r, seed).
size_t find_first_unused(size_t start) const noexcept
uint64_t rem_mask() const noexcept
bool is_run_start(const size_t i) const noexcept
size_t size() const noexcept
Number of elements.
bool contains(const T &item) const noexcept
Test membership.
bool get_cont(size_t i) const noexcept
void set_element(const size_t i, const bool cont, const bool shft, const uint64_t rem) noexcept
std::pair< size_t, uint64_t > fingerprint(const T &item) const
static constexpr uint64_t SHFT_BIT
static constexpr uint64_t OCC_BIT
static constexpr uint64_t META_MASK
uint32_t seed() const noexcept
Hash seed.
bool slot_empty(size_t i) const noexcept
Quotient_Filter(uint8_t q, uint8_t r, uint32_t seed=0x5F3759DF)
Construct a quotient filter.
void shift_elements_right(size_t pos, size_t empty) 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.
size_t find_run_start(size_t fq) const noexcept
void set_cont(const size_t i, const bool v) noexcept
bool remove(const T &item) noexcept
Remove an element.
void clear() noexcept
Remove all elements.
void shift_elements_left(size_t pos) noexcept
void clear_element(const size_t i) noexcept
void swap(Quotient_Filter &other) noexcept
Swap in O(1).
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)
Dynamic array container with automatic resizing.