ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::CuckooFilter< T, F, H > Class Template Reference

a dynamic filter of the keys of type T with fingerprints of type F (8 or 16 bits), 2 buckets of 4 places per key More...

#include <ADS/set/CuckooFilter.h>

Public member functions

 CuckooFilter (void)
 a filter for one key, empty
 CuckooFilter (std::size_t n, H h=H())
 the empty filter for \( n \) keys, at the load 0.94 when they are in, in at least one bucket: \( 2^\ell \) buckets, the least power of 2 with \( 4 \cdot 0.94 \cdot 2^\ell \ge n \)
bool insert (const T &x)
 \( x \) into the filter by insertHash() of its hash, false (and nothing changed) if the filter is full
bool remove (const T &x)
 one insertion of \( x \) removed by removeHash() of its hash, false if \( x \) is not there
bool maybe (const T &x) const
 whether \( x \) may be in the set, by maybeHash() of its hash: false only if \( x \) is not in the set
bool insertHash (std::uint64_t h)
 the hash \( h \) of 64 bits, which must be random, into the filter, false (and nothing changed) if the filter is full
bool removeHash (std::uint64_t h)
 one insertion of the hash \( h \) removed, false if it is not there
bool maybeHash (std::uint64_t h) const
 whether the hash \( h \) may be in the set: false only if it is not
void clear (void)
 removes all the keys
std::size_t size (void) const
 the keys in, with their repetitions
bool empty (void) const
 whether no key is in
std::size_t capacity (void) const
 the places, 4 per bucket
double load (void) const
 size() / capacity(), the load \( \alpha \)
std::size_t bits (void) const
 the bits of the buckets
template<class A>
void persist (A &a)
 the members written to, or read from, the archive \( a \) [see Persistence.h]

Static public member functions

static constexpr std::uint64_t persistTag (void)
 the parameters of the layout, in a file

Static public attributes

static constexpr std::string_view persistName = "CuckooFilter"
 the name of the structure in a file [see Persistence.h]

Detailed description

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
class ADS::CuckooFilter< T, F, H >

a dynamic filter of the keys of type T with fingerprints of type F (8 or 16 bits), 2 buckets of 4 places per key

Constructor and destructor documentation

◆ CuckooFilter() [1/2]

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
ADS::CuckooFilter< T, F, H >::CuckooFilter ( void )
inline

a filter for one key, empty

◆ CuckooFilter() [2/2]

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
ADS::CuckooFilter< T, F, H >::CuckooFilter ( std::size_t n,
H h = H() )
explicit

the empty filter for \( n \) keys, at the load 0.94 when they are in, in at least one bucket: \( 2^\ell \) buckets, the least power of 2 with \( 4 \cdot 0.94 \cdot 2^\ell \ge n \)

Precondition
\( n < 2^{32} \)

Member function documentation

◆ bits()

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
std::size_t ADS::CuckooFilter< T, F, H >::bits ( void ) const
nodiscard

the bits of the buckets

◆ capacity()

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
std::size_t ADS::CuckooFilter< T, F, H >::capacity ( void ) const
nodiscard

the places, 4 per bucket

◆ clear()

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
void ADS::CuckooFilter< T, F, H >::clear ( void )

removes all the keys

◆ empty()

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
bool ADS::CuckooFilter< T, F, H >::empty ( void ) const
nodiscard

whether no key is in

◆ insert()

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
bool ADS::CuckooFilter< T, F, H >::insert ( const T & x)

\( x \) into the filter by insertHash() of its hash, false (and nothing changed) if the filter is full

Postcondition
maybe( x ) if true

◆ insertHash()

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
bool ADS::CuckooFilter< T, F, H >::insertHash ( std::uint64_t h)

the hash \( h \) of 64 bits, which must be random, into the filter, false (and nothing changed) if the filter is full

In pseudocode (Fan, Andersen, Kaminsky and Mitzenmacher, with the stash of one entry of Kirsch, Mitzenmacher and Wieder), \( v \) the victim:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{insertHash}( h ) \cr 2 & \quad \textbf{if}\ v \ne \textbf{nil}\ \textbf{then return false} \cr 3 & \quad t \gets t( h );\ b \gets h_1( h ) \bmod 2^\ell \cr 4 & \quad \textbf{if}\ \text{a place of } b \text{ or of } b \oplus g( t ) \text{ is free }\ \textbf{then}\ \text{put } t \text{ there}; \ \textbf{return true} \cr 5 & \quad b \gets b \text{ or } b \oplus g( t ) \text{, at random} \cr 6 & \quad \textbf{for}\ i \gets 1\ \textbf{to}\ 500\ \textbf{do} \cr 7 & \qquad \text{swap } t \text{ with the fingerprint of a random } \text{place of } b \cr 8 & \qquad b \gets b \oplus g( t ) \cr 9 & \qquad \textbf{if}\ \text{a place of } b \text{ is free } \ \textbf{then}\ \text{put } t \text{ there};\ \textbf{return true} \cr 10 & \quad v \gets ( b , t );\ \textbf{return true} \end{array}} \]

◆ load()

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
double ADS::CuckooFilter< T, F, H >::load ( void ) const
nodiscard

size() / capacity(), the load \( \alpha \)

◆ maybe()

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
bool ADS::CuckooFilter< T, F, H >::maybe ( const T & x) const
nodiscard

whether \( x \) may be in the set, by maybeHash() of its hash: false only if \( x \) is not in the set

◆ maybeHash()

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
bool ADS::CuckooFilter< T, F, H >::maybeHash ( std::uint64_t h) const
nodiscard

whether the hash \( h \) may be in the set: false only if it is not

In pseudocode (Fan et al.), the 4 places of a bucket tested at once by the test of a zero lane:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{maybeHash}( h ) \cr 2 & \quad t \gets t( h );\ b_1 \gets h_1( h ) \bmod 2^\ell;\ b_2 \gets b_1 \oplus g( t ) \cr 3 & \quad \textbf{return}\ t \text{ is in a place of } b_1 \text{ or } b_2 \text{, or } v \in \{ ( b_1 , t ) , ( b_2 , t ) \} \end{array}} \]

◆ persist()

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
template<class A>
void ADS::CuckooFilter< T, F, H >::persist ( A & a)

the members written to, or read from, the archive \( a \) [see Persistence.h]

◆ persistTag()

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
constexpr std::uint64_t ADS::CuckooFilter< T, F, H >::persistTag ( void )
inlinestaticnodiscardconstexpr

the parameters of the layout, in a file

◆ remove()

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
bool ADS::CuckooFilter< T, F, H >::remove ( const T & x)

one insertion of \( x \) removed by removeHash() of its hash, false if \( x \) is not there

Precondition
\( x \) was inserted (otherwise another key may be lost)

◆ removeHash()

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
bool ADS::CuckooFilter< T, F, H >::removeHash ( std::uint64_t h)

one insertion of the hash \( h \) removed, false if it is not there

In pseudocode (Fan et al.):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{removeHash}( h ) \cr 2 & \quad t \gets t( h );\ b_1 \gets h_1( h ) \bmod 2^\ell;\ b_2 \gets b_1 \oplus g( t ) \cr 3 & \quad \textbf{foreach}\ b \in \{ b_1 , b_2 \}\ \textbf{do} \cr 4 & \qquad \textbf{if}\ \text{a place of } b \text{ holds } t \ \textbf{then} \cr 5 & \qquad\quad \text{clear it} \cr 6 & \qquad\quad \textbf{if}\ v = ( b' , t' ) \ne \textbf{nil} \ \textbf{then}\ v \gets \textbf{nil};\ \text{place } t' \text{ from } b' \text{ as in insertHash} \cr 7 & \qquad\quad \textbf{return true} \cr 8 & \quad \textbf{if}\ v = ( b_1 , t ) \text{ or } ( b_2 , t ) \ \textbf{then}\ v \gets \textbf{nil};\ \textbf{return true} \cr 9 & \quad \textbf{return false} \end{array}} \]

◆ size()

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
std::size_t ADS::CuckooFilter< T, F, H >::size ( void ) const
nodiscard

the keys in, with their repetitions

Member data documentation

◆ persistName

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
std::string_view ADS::CuckooFilter< T, F, H >::persistName = "CuckooFilter"
staticconstexpr

the name of the structure in a file [see Persistence.h]


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