|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Industrial-grade Cuckoo Filter implementation. More...
#include <cuckoo-filter.H>
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. | |
| Cuckoo_Filter (const Cuckoo_Filter &other)=default | |
| Copy the buckets, the stash and the generator of another filter. | |
| Cuckoo_Filter (Cuckoo_Filter &&other) | |
| Take the items of another filter, which is left as an empty filter of one bucket. | |
| Cuckoo_Filter & | operator= (const Cuckoo_Filter &other)=default |
| Copy the buckets, the stash and the generator of another filter. | |
| Cuckoo_Filter & | operator= (Cuckoo_Filter &&other) noexcept |
| Exchange this filter with another, which is left with the previous state of this one. | |
| void | swap (Cuckoo_Filter &other) noexcept |
| Exchange in O(1) the state of this filter and another. | |
| 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< 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 |
Industrial-grade Cuckoo Filter implementation.
std::vector copies these objects instead of moving them: their move constructor is not noexcept, because it leaves the source empty and usable, which allocates, and std::vector moves only what cannot throw. DynList holds them without relocating them, so it never copies them; Array and DynArray cannot hold them, as they build their items by default and these objects have no default constructor. Definition at line 107 of file cuckoo-filter.H.
|
private |
Definition at line 112 of file cuckoo-filter.H.
|
inlineexplicit |
Construct a 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. |
| std::overflow_error | if the capacity asks for more buckets than a size_t counts, or than their array holds. |
Definition at line 227 of file cuckoo-filter.H.
References ah_overflow_error_if, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::bucket_mask, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::buckets, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::capacity(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::kTargetLoad, Aleph::next_power_of_2(), and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_buckets.
|
default |
Copy the buckets, the stash and the generator of another filter.
| [in] | other | filter to copy. |
| std::bad_alloc | if the buckets cannot be allocated. |
|
inline |
Take the items of another filter, which is left as an empty filter of one bucket.
The implicit move took the buckets but copied their count and their mask: the moved-from filter then indexed buckets that it no longer had. With one bucket, every operation of other works as in any filter, with no test for a filter without buckets. other draws its kicks from a copy of its generator.
| [in,out] | other | filter to move from. |
| std::bad_alloc | if the bucket left to other cannot be allocated; other is then unchanged. |
other. Definition at line 270 of file cuckoo-filter.H.
References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::buckets, and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::swap().
|
inlineprivate |
Definition at line 207 of file cuckoo-filter.H.
References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::bucket_mask, and Aleph::murmur3hash().
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), and Aleph::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 426 of file cuckoo-filter.H.
References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert().
|
inlinenoexcept |
Return the total number of fingerprint slots (including stash).
| none. |
Definition at line 340 of file cuckoo-filter.H.
References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_buckets, and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_size.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::Cuckoo_Filter(), example_memory_optimization(), example_performance(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::load_factor(), and TEST().
|
inline |
Clear the filter.
| none. |
Definition at line 488 of file cuckoo-filter.H.
References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::buckets, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_buckets, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items, and Aleph::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 438 of file cuckoo-filter.H.
References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::alt_index(), Aleph::and, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::buckets, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::get_fingerprint(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::index_hash(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_, and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_count_.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains(), example_performance(), TEST(), TEST(), and TEST().
|
inlinenoexcept |
Return whether the filter contains no items.
true if the filter has no items. | none. |
Definition at line 322 of file cuckoo-filter.H.
References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::is_empty().
|
inlineprivate |
Definition at line 194 of file cuckoo-filter.H.
References Aleph::dft_hash_fct(), and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::fp_mask.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove().
|
inlineprivatenoexcept |
Definition at line 202 of file cuckoo-filter.H.
References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::bucket_mask, and Aleph::dft_hash_fct().
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), and Aleph::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 361 of file cuckoo-filter.H.
References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::alt_index(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::buckets, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::get_fingerprint(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::index_hash(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::max_kicks, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::rng_, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_count_, and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_size.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::append(), example_performance(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), TEST(), TEST(), and TEST().
|
inlinenoexcept |
Synonym for empty() in traditional Aleph style.
true if the filter has no items. | none. |
Definition at line 331 of file cuckoo-filter.H.
References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::empty().
|
inlinenoexcept |
Return the load factor of the filter (relative to capacity()).
| none. |
Definition at line 349 of file cuckoo-filter.H.
References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::capacity(), and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items.
|
default |
Copy the buckets, the stash and the generator of another filter.
| [in] | other | filter to copy. |
| std::bad_alloc | if the buckets cannot be allocated. |
|
inlinenoexcept |
Exchange this filter with another, which is left with the previous state of this one.
| [in,out] | other | filter to move from. |
Definition at line 289 of file cuckoo-filter.H.
References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::swap().
|
inline |
Remove an item from the filter.
| item | Item to remove. |
true if an instance of the item was removed. | none. |
Definition at line 461 of file cuckoo-filter.H.
References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::alt_index(), Aleph::and, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::buckets, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::get_fingerprint(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::index_hash(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_, and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_count_.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove().
|
inlinenoexcept |
Return the number of items currently in the filter.
| none. |
Definition at line 313 of file cuckoo-filter.H.
References Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items.
|
inlinenoexcept |
Exchange in O(1) the state of this filter and another.
| [in,out] | other | filter to exchange with. |
Definition at line 298 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 >::num_buckets, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::num_items, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::rng_, Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_, and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::stash_count_.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::Cuckoo_Filter(), and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::operator=().
|
private |
Definition at line 182 of file cuckoo-filter.H.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::Cuckoo_Filter(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::alt_index(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::index_hash(), and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::swap().
|
private |
Definition at line 179 of file cuckoo-filter.H.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::Cuckoo_Filter(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::Cuckoo_Filter(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::clear(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove(), and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::swap().
|
staticconstexprprivate |
Definition at line 192 of file cuckoo-filter.H.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::get_fingerprint().
|
staticconstexprprivate |
Definition at line 187 of file cuckoo-filter.H.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::Cuckoo_Filter().
|
staticconstexprprivate |
Definition at line 185 of file cuckoo-filter.H.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert().
|
private |
Definition at line 181 of file cuckoo-filter.H.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::Cuckoo_Filter(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::capacity(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::clear(), and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::swap().
|
private |
Definition at line 180 of file cuckoo-filter.H.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::clear(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::empty(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::load_factor(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::size(), and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::swap().
|
mutableprivate |
Definition at line 183 of file cuckoo-filter.H.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::swap().
|
private |
Definition at line 188 of file cuckoo-filter.H.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove(), and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::swap().
|
private |
Definition at line 189 of file cuckoo-filter.H.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::clear(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::contains(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert(), Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::remove(), and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::swap().
|
staticconstexprprivate |
Definition at line 186 of file cuckoo-filter.H.
Referenced by Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::capacity(), and Aleph::Cuckoo_Filter< T, FingerprintBits, EntriesPerBucket >::insert().