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

Industrial-grade Cuckoo Filter implementation. More...

#include <cuckoo-filter.H>

Collaboration diagram for Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >:
[legend]

Classes

struct  Bucket
 
struct  Victim
 Victim entry: a fingerprint displaced during a failed kick chain. More...
 

Public Member Functions

 Cuckoo_Filter (size_t capacity, std::optional< std::uint32_t > seed=std::nullopt)
 Construct a Cuckoo Filter with a given capacity.
 
size_t size () const noexcept
 Return the number of items currently in the filter.
 
bool empty () const noexcept
 Return whether the filter contains no items.
 
bool is_empty () const noexcept
 Synonym for empty() in traditional Aleph style.
 
size_t capacity () const noexcept
 Return the total number of fingerprint slots (including stash).
 
double load_factor () const noexcept
 Return the load factor of the filter (relative to capacity()).
 
bool insert (const T &item)
 Insert an item into the filter.
 
bool append (const T &item)
 Alias for insert().
 
bool contains (const T &item) const
 Test membership.
 
bool remove (const T &item)
 Remove an item from the filter.
 
void clear ()
 Clear the filter.
 

Private Types

using Fingerprint = uint32_t
 

Private Member Functions

Fingerprint get_fingerprint (const T &item) const
 
size_t index_hash (const T &item) const noexcept
 
size_t alt_index (size_t i, Fingerprint fp) const
 

Private Attributes

Aleph::Array< Bucketbuckets
 
size_t num_items = 0
 
size_t num_buckets = 0
 
size_t bucket_mask = 0
 
std::mt19937 rng_
 
Victim stash_ [stash_size] = {}
 
size_t stash_count_ = 0
 

Static Private Attributes

static constexpr size_t max_kicks = 500
 
static constexpr size_t stash_size = 4
 
static constexpr double kTargetLoad = 0.9
 
static constexpr Fingerprint fp_mask = (FingerprintBits == 32) ? 0xFFFFFFFF : (1U << FingerprintBits) - 1
 

Detailed Description

template<typename T, size_t FingerprintBits = 8, size_t EntriesPerBucket = 4>
class Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >

Industrial-grade Cuckoo Filter implementation.

Note
Not thread-safe. Concurrent reads (contains / size / etc.) are safe; any concurrent write (insert / remove / clear) requires external synchronisation.

Definition at line 98 of file cuckoo-filter.H.

Member Typedef Documentation

◆ Fingerprint

template<typename T , size_t FingerprintBits = 8, size_t EntriesPerBucket = 4>
using Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::Fingerprint = uint32_t
private

Definition at line 103 of file cuckoo-filter.H.

Constructor & Destructor Documentation

◆ Cuckoo_Filter()

template<typename T , size_t FingerprintBits = 8, size_t EntriesPerBucket = 4>
Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::Cuckoo_Filter ( size_t  capacity,
std::optional< std::uint32_t >  seed = std::nullopt 
)
inlineexplicit

Construct a Cuckoo Filter with a given capacity.

Parameters
capacityMinimum number of items to support.
seedOptional RNG seed for deterministic kick sequences. Pass a fixed value in tests to eliminate flakiness. Defaults to a non-deterministic device seed.
Exceptions
std::bad_allocif memory allocation fails.
Note
O(capacity / EntriesPerBucket).

Definition at line 216 of file cuckoo-filter.H.

References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::bucket_mask, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::buckets, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::capacity(), Aleph::divide_and_conquer_partition_dp(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::kTargetLoad, Aleph::next_power_of_2(), and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_buckets.

Member Function Documentation

◆ alt_index()

◆ append()

template<typename T , size_t FingerprintBits = 8, size_t EntriesPerBucket = 4>
bool Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::append ( const T item)
inline

Alias for insert().

Parameters
itemItem to insert.
Returns
true if insertion succeeded, false if filter is full.
Exceptions
none.

Definition at line 348 of file cuckoo-filter.H.

References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert().

◆ capacity()

◆ clear()

◆ contains()

◆ empty()

template<typename T , size_t FingerprintBits = 8, size_t EntriesPerBucket = 4>
bool Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::empty ( ) const
inlinenoexcept

Return whether the filter contains no items.

Returns
true if the filter has no items.
Exceptions
none.

Definition at line 244 of file cuckoo-filter.H.

References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items.

Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::is_empty().

◆ get_fingerprint()

◆ index_hash()

◆ insert()

◆ is_empty()

template<typename T , size_t FingerprintBits = 8, size_t EntriesPerBucket = 4>
bool Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::is_empty ( ) const
inlinenoexcept

Synonym for empty() in traditional Aleph style.

Returns
true if the filter has no items.
Exceptions
none.

Definition at line 253 of file cuckoo-filter.H.

References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::empty().

◆ load_factor()

template<typename T , size_t FingerprintBits = 8, size_t EntriesPerBucket = 4>
double Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::load_factor ( ) const
inlinenoexcept

Return the load factor of the filter (relative to capacity()).

Returns
Ratio of stored items to total slots.
Exceptions
none.

Definition at line 271 of file cuckoo-filter.H.

References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::capacity(), and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items.

◆ remove()

◆ size()

template<typename T , size_t FingerprintBits = 8, size_t EntriesPerBucket = 4>
size_t Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::size ( ) const
inlinenoexcept

Return the number of items currently in the filter.

Returns
Current item count.
Exceptions
none.

Definition at line 235 of file cuckoo-filter.H.

References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items.

Referenced by TEST(), and TEST().

Member Data Documentation

◆ bucket_mask

◆ buckets

◆ fp_mask

template<typename T , size_t FingerprintBits = 8, size_t EntriesPerBucket = 4>
constexpr Fingerprint Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::fp_mask = (FingerprintBits == 32) ? 0xFFFFFFFF : (1U << FingerprintBits) - 1
staticconstexprprivate

◆ kTargetLoad

template<typename T , size_t FingerprintBits = 8, size_t EntriesPerBucket = 4>
constexpr double Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::kTargetLoad = 0.9
staticconstexprprivate

◆ max_kicks

template<typename T , size_t FingerprintBits = 8, size_t EntriesPerBucket = 4>
constexpr size_t Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::max_kicks = 500
staticconstexprprivate

◆ num_buckets

◆ num_items

◆ rng_

template<typename T , size_t FingerprintBits = 8, size_t EntriesPerBucket = 4>
std::mt19937 Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::rng_
mutableprivate

◆ stash_

◆ stash_count_

◆ stash_size

template<typename T , size_t FingerprintBits = 8, size_t EntriesPerBucket = 4>
constexpr size_t Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_size = 4
staticconstexprprivate

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