|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Memory-optimized Cuckoo Filter with bit-packed fingerprints. More...
#include <compact-cuckoo-filter.H>
Classes | |
| struct | Bucket |
| struct | Victim |
| Victim entry: a fingerprint that was displaced during a failed insert. More... | |
Public Member Functions | |
| Compact_Cuckoo_Filter (size_t capacity, const std::optional< std::uint32_t > seed=std::nullopt) | |
| Construct a Compact 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()). | |
| size_t | memory_usage () const noexcept |
| Return approximate memory usage in bytes. | |
| 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 (const size_t i, Fingerprint fp) const |
Private Attributes | |
| Aleph::Array< Bucket > | buckets |
| 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 |
Memory-optimized Cuckoo Filter with bit-packed fingerprints.
Definition at line 94 of file compact-cuckoo-filter.H.
|
private |
Definition at line 99 of file compact-cuckoo-filter.H.
|
inlineexplicit |
Construct a Compact Cuckoo Filter with a given capacity.
| capacity | Minimum number of items to support. |
| seed | Optional RNG seed for deterministic kick sequences. Pass a fixed value in tests to eliminate flakiness. Defaults to a non-deterministic device seed. |
| std::bad_alloc | if memory allocation fails. |
Definition at line 236 of file compact-cuckoo-filter.H.
References Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::bucket_mask, Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::buckets, Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::capacity(), Aleph::divide_and_conquer_partition_dp(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::kTargetLoad, Aleph::next_power_of_2(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_buckets.
|
inlineprivate |
Definition at line 218 of file compact-cuckoo-filter.H.
References Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::bucket_mask, and Aleph::murmur3hash().
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove().
|
inline |
Alias for insert().
| item | Item to insert. |
true if insertion succeeded, false if filter is full. | none. |
Definition at line 379 of file compact-cuckoo-filter.H.
References Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert().
|
inlinenoexcept |
Return the total number of fingerprint slots (including stash).
| none. |
Definition at line 281 of file compact-cuckoo-filter.H.
References Aleph::divide_and_conquer_partition_dp(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_buckets, and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_size.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::Compact_Cuckoo_Filter(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::load_factor().
|
inline |
Clear the filter.
| none. |
Definition at line 442 of file compact-cuckoo-filter.H.
References Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::buckets, Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_buckets, Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items, and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_count_.
|
inline |
Test membership.
| item | Item to check. |
true if item is likely present, false if definitely not. | none. |
Definition at line 391 of file compact-cuckoo-filter.H.
References Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::alt_index(), Aleph::and, Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::buckets, Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains(), Aleph::divide_and_conquer_partition_dp(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::get_fingerprint(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::index_hash(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_, and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_count_.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains().
|
inlinenoexcept |
Return whether the filter contains no items.
true if the filter has no items. | none. |
Definition at line 263 of file compact-cuckoo-filter.H.
References Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::is_empty().
|
inlineprivate |
Definition at line 205 of file compact-cuckoo-filter.H.
References Aleph::dft_hash_fct(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::fp_mask.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove().
|
inlineprivatenoexcept |
Definition at line 213 of file compact-cuckoo-filter.H.
References Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::bucket_mask, and Aleph::dft_hash_fct().
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove().
|
inline |
Insert an item into the filter.
| item | Item to insert. |
true if insertion succeeded, false if filter is full. | none. |
Definition at line 314 of file compact-cuckoo-filter.H.
References Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::alt_index(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::buckets, Aleph::divide_and_conquer_partition_dp(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::get_fingerprint(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::index_hash(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::max_kicks, Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items, Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::rng_, Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_, Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_count_, and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_size.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::append(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert().
|
inlinenoexcept |
Synonym for empty() in traditional Aleph style.
true if the filter has no items. | none. |
Definition at line 272 of file compact-cuckoo-filter.H.
References Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::empty().
|
inlinenoexcept |
Return the load factor of the filter (relative to capacity()).
| none. |
Definition at line 290 of file compact-cuckoo-filter.H.
References Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::capacity(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items.
|
inlinenoexcept |
Return approximate memory usage in bytes.
| none. |
Definition at line 299 of file compact-cuckoo-filter.H.
References Aleph::divide_and_conquer_partition_dp(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_buckets.
Referenced by example_custom_fingerprints().
|
inline |
Remove an item from the filter.
| item | Item to remove. |
true if an instance of the item was removed. | none. |
Definition at line 414 of file compact-cuckoo-filter.H.
References Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::alt_index(), Aleph::and, Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::buckets, Aleph::divide_and_conquer_partition_dp(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::get_fingerprint(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::index_hash(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items, Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_, and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_count_.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove().
|
inlinenoexcept |
Return the number of items currently in the filter.
| none. |
Definition at line 254 of file compact-cuckoo-filter.H.
References Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items.
|
private |
Definition at line 193 of file compact-cuckoo-filter.H.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::Compact_Cuckoo_Filter(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::alt_index(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::index_hash().
|
private |
Definition at line 190 of file compact-cuckoo-filter.H.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::Compact_Cuckoo_Filter(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::clear(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove().
|
staticconstexprprivate |
Definition at line 203 of file compact-cuckoo-filter.H.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::get_fingerprint().
|
staticconstexprprivate |
Definition at line 198 of file compact-cuckoo-filter.H.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::Compact_Cuckoo_Filter().
|
staticconstexprprivate |
Definition at line 196 of file compact-cuckoo-filter.H.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert().
|
private |
Definition at line 192 of file compact-cuckoo-filter.H.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::Compact_Cuckoo_Filter(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::capacity(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::clear(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::memory_usage().
|
private |
Definition at line 191 of file compact-cuckoo-filter.H.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::clear(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::empty(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::load_factor(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::size().
|
mutableprivate |
Definition at line 194 of file compact-cuckoo-filter.H.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert().
|
private |
Definition at line 199 of file compact-cuckoo-filter.H.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove().
|
private |
Definition at line 200 of file compact-cuckoo-filter.H.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::clear(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains(), Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove().
|
staticconstexprprivate |
Definition at line 197 of file compact-cuckoo-filter.H.
Referenced by Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::capacity(), and Aleph::Compact_Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert().