Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Compact_Quotient_Filter< T > Class Template Reference

Memory-optimized quotient filter with bit-packed slots. More...

#include <compact-quotient-filter.H>

Collaboration diagram for Aleph::Compact_Quotient_Filter< T >:
[legend]

Public Member Functions

 Compact_Quotient_Filter (uint8_t q, uint8_t r, uint32_t seed=0x5F3759DF)
 Construct a compact quotient filter.
 
Compact_Quotient_Filterinsert (const T &item)
 Insert an element.
 
bool contains (const T &item) const noexcept
 Test membership.
 
bool remove (const T &item) noexcept
 Remove an element.
 
size_t size () const noexcept
 Number of elements.
 
size_t capacity () const noexcept
 Number of slots (2^q).
 
double load_factor () const noexcept
 Current load factor.
 
bool is_empty () const noexcept
 True if empty.
 
uint8_t q () const noexcept
 Quotient bits.
 
uint8_t r () const noexcept
 Remainder bits.
 
double false_positive_rate () const noexcept
 Theoretical FP probability ~ 2^{-r}.
 
uint32_t seed () const noexcept
 Hash seed.
 
size_t memory_usage () const noexcept
 Memory usage in bytes.
 
void clear () noexcept
 Remove all elements.
 
void merge (const Compact_Quotient_Filter &other)
 Merge another filter (same q, r, seed).
 
void swap (Compact_Quotient_Filter &other) noexcept
 Swap in O(1).
 

Static Public Member Functions

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.
 
static std::pair< uint8_t, uint8_testimate (size_t n, double fp_rate)
 Estimate (q, r) for n elements and target FP rate.
 

Private Member Functions

size_t bits_per_slot () const noexcept
 
size_t slot_offset (const size_t i) const noexcept
 
uint64_t rem_mask () const noexcept
 
bool get_bit_at (const size_t slot, const size_t bit_idx) const noexcept
 
void set_bit_at (const size_t slot, const size_t bit_idx, const bool v) noexcept
 
bool get_occ (const size_t i) const noexcept
 
bool get_cont (const size_t i) const noexcept
 
bool get_shft (const size_t i) const noexcept
 
bool slot_empty (const size_t i) const noexcept
 
bool has_element (const size_t i) const noexcept
 
bool is_run_start (const size_t i) const noexcept
 
void set_occ (const size_t i, const bool v) noexcept
 
void set_cont (const size_t i, const bool v) noexcept
 
void set_shft (const size_t i, const bool v) noexcept
 
uint64_t get_rem (const size_t i) const noexcept
 
void set_rem (const size_t i, const uint64_t rem) noexcept
 
void set_element (const size_t i, const bool cont, const bool shft, const uint64_t rem) noexcept
 
void clear_element (const size_t i) noexcept
 
size_t incr (const size_t i) const noexcept
 
size_t decr (const size_t i) const noexcept
 
std::pair< size_t, uint64_tfingerprint (const T &item) const
 
size_t find_run_start (const size_t fq) const noexcept
 
size_t find_first_unused (const size_t start) 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)
 
void shift_elements_left (const size_t pos) noexcept
 

Private Attributes

uint8_t q_
 
uint8_t r_
 
size_t num_slots_
 
size_t num_elems_
 
uint32_t seed_
 
BitArray bits_
 

Detailed Description

template<typename T>
class Aleph::Compact_Quotient_Filter< T >

Memory-optimized quotient filter with bit-packed slots.

Template Parameters
TElement type. Must be hashable via murmur3hash(T, seed).

Definition at line 85 of file compact-quotient-filter.H.

Constructor & Destructor Documentation

◆ Compact_Quotient_Filter()

template<typename T >
Aleph::Compact_Quotient_Filter< T >::Compact_Quotient_Filter ( uint8_t  q,
uint8_t  r,
uint32_t  seed = 0x5F3759DF 
)
inline

Construct a compact quotient filter.

Parameters
[in]qNumber of quotient bits (2^q slots). Must be in [1, 32].
[in]rRemainder bits per slot (FP rate ~ 2^{-r}). Must be in [1, 60].
[in]seedHash seed (default: 0x5F3759DF).
Exceptions
std::domain_errorif q or r are out of range, or q + r > 64.

Definition at line 360 of file compact-quotient-filter.H.

References ah_domain_error_if, Aleph::Compact_Quotient_Filter< T >::bits_, Aleph::Compact_Quotient_Filter< T >::bits_per_slot(), Aleph::divide_and_conquer_partition_dp(), Aleph::Compact_Quotient_Filter< T >::num_slots_, Aleph::Compact_Quotient_Filter< T >::q(), Aleph::Compact_Quotient_Filter< T >::r(), and Aleph::BitArray::reserve().

Member Function Documentation

◆ bits_per_slot()

◆ capacity()

template<typename T >
size_t Aleph::Compact_Quotient_Filter< T >::capacity ( ) const
inlinenoexcept

Number of slots (2^q).

O(1).

Definition at line 501 of file compact-quotient-filter.H.

References Aleph::Compact_Quotient_Filter< T >::num_slots_.

◆ clear()

◆ clear_element()

◆ contains()

◆ decr()

◆ do_insert()

◆ estimate()

template<typename T >
static std::pair< uint8_t, uint8_t > Aleph::Compact_Quotient_Filter< T >::estimate ( size_t  n,
double  fp_rate 
)
inlinestatic

Estimate (q, r) for n elements and target FP rate.

Definition at line 580 of file compact-quotient-filter.H.

References ah_domain_error_if, and Aleph::divide_and_conquer_partition_dp().

Referenced by TEST().

◆ false_positive_rate()

template<typename T >
double Aleph::Compact_Quotient_Filter< T >::false_positive_rate ( ) const
inlinenoexcept

Theoretical FP probability ~ 2^{-r}.

Definition at line 531 of file compact-quotient-filter.H.

References Aleph::Compact_Quotient_Filter< T >::r_.

◆ find_first_unused()

template<typename T >
size_t Aleph::Compact_Quotient_Filter< T >::find_first_unused ( const size_t  start) const
inlineprivatenoexcept

◆ find_run_start()

◆ fingerprint()

◆ from_capacity()

template<typename T >
static Compact_Quotient_Filter Aleph::Compact_Quotient_Filter< T >::from_capacity ( size_t  expected_n,
double  fp_rate,
uint32_t  seed = 0x5F3759DF 
)
inlinestatic

Construct from desired capacity and false positive rate.

Parameters
[in]expected_nExpected number of elements.
[in]fp_rateTarget false positive probability.
[in]seedHash seed.
Exceptions
std::domain_errorif expected_n == 0, fp_rate not in (0,1), or the requested (expected_n, fp_rate) cannot be represented within the supported parameter ranges.

Definition at line 384 of file compact-quotient-filter.H.

References ah_domain_error_if, Aleph::divide_and_conquer_partition_dp(), and Aleph::Compact_Quotient_Filter< T >::seed().

Referenced by example_from_capacity(), example_url_deduplication(), and TEST().

◆ get_bit_at()

◆ get_cont()

◆ get_occ()

◆ get_rem()

◆ get_shft()

◆ has_element()

◆ incr()

◆ insert()

template<typename T >
Compact_Quotient_Filter & Aleph::Compact_Quotient_Filter< T >::insert ( const T item)
inline

Insert an element.

After insertion, contains(item) is guaranteed true. Duplicates are silently ignored.

Exceptions
std::overflow_errorif the filter is full.

Definition at line 418 of file compact-quotient-filter.H.

References ah_overflow_error_if, Aleph::divide_and_conquer_partition_dp(), Aleph::Compact_Quotient_Filter< T >::do_insert(), Aleph::Compact_Quotient_Filter< T >::fingerprint(), Aleph::Compact_Quotient_Filter< T >::num_elems_, and Aleph::Compact_Quotient_Filter< T >::num_slots_.

Referenced by TEST(), TEST(), and TEST().

◆ is_empty()

template<typename T >
bool Aleph::Compact_Quotient_Filter< T >::is_empty ( ) const
inlinenoexcept

True if empty.

O(1).

Definition at line 513 of file compact-quotient-filter.H.

References Aleph::Compact_Quotient_Filter< T >::num_elems_.

◆ is_run_start()

◆ load_factor()

template<typename T >
double Aleph::Compact_Quotient_Filter< T >::load_factor ( ) const
inlinenoexcept

◆ memory_usage()

template<typename T >
size_t Aleph::Compact_Quotient_Filter< T >::memory_usage ( ) const
inlinenoexcept

◆ merge()

template<typename T >
void Aleph::Compact_Quotient_Filter< T >::merge ( const Compact_Quotient_Filter< T > &  other)
inline

◆ q()

template<typename T >
uint8_t Aleph::Compact_Quotient_Filter< T >::q ( ) const
inlinenoexcept

◆ r()

template<typename T >
uint8_t Aleph::Compact_Quotient_Filter< T >::r ( ) const
inlinenoexcept

◆ rem_mask()

template<typename T >
uint64_t Aleph::Compact_Quotient_Filter< T >::rem_mask ( ) const
inlineprivatenoexcept

◆ remove()

◆ seed()

template<typename T >
uint32_t Aleph::Compact_Quotient_Filter< T >::seed ( ) const
inlinenoexcept

◆ set_bit_at()

◆ set_cont()

◆ set_element()

◆ set_occ()

◆ set_rem()

◆ set_shft()

◆ shift_elements_left()

◆ shift_elements_right()

◆ size()

template<typename T >
size_t Aleph::Compact_Quotient_Filter< T >::size ( ) const
inlinenoexcept

Number of elements.

O(1).

Definition at line 495 of file compact-quotient-filter.H.

References Aleph::Compact_Quotient_Filter< T >::num_elems_.

◆ slot_empty()

◆ slot_offset()

◆ swap()

Member Data Documentation

◆ bits_

◆ num_elems_

◆ num_slots_

◆ q_

◆ r_

◆ seed_


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