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

an incremental filter of at most \( n \) keys of type T: bins of 25 fingerprints of 8 bits over 25 quotients, the overflow in a spare More...

#include <ADS/set/PrefixFilter.h>

Public member functions

 PrefixFilter (void)
 a filter for one key, empty
 PrefixFilter (std::size_t n, H h=H())
 the empty filter for \( n \) keys, its bins at the load 0.95 when they are in, at least one bin
bool insert (const T &x)
 \( x \) into the filter by insertHash() of its hash, false (and nothing changed) if \( n \) keys are in
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 \( n \) keys are in
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 keys that fit, the \( n \) of the constructor
double load (void) const
 size() / ( 25 bins() ), at most about 0.95
std::size_t bits (void) const
 the bits of the bins and of the spare
std::size_t bins (void) const
 the bins, of 256 bits each
std::size_t spareSize (void) const
 the fingerprints sent to the spare
double expectedSpareSize (void) const
 the expected fingerprints sent to the spare when capacity() keys are in, \( \mathrm{E}[ X ] = n - m \, \mathrm{E}[ \min( B , 25 ) ] \)
double falsePositiveRate (void) const
 the expected false positives at the current load, the sum of the analysis of PrefixFilter.h over the loads \( j \) of a bin
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 = "PrefixFilter"
 the name of the structure in a file [see Persistence.h]

Detailed description

template<class T, class H = DefaultHash< T >>
class ADS::PrefixFilter< T, H >

an incremental filter of at most \( n \) keys of type T: bins of 25 fingerprints of 8 bits over 25 quotients, the overflow in a spare

Constructor and destructor documentation

◆ PrefixFilter() [1/2]

template<class T, class H = DefaultHash< T >>
ADS::PrefixFilter< T, H >::PrefixFilter ( void )
inline

a filter for one key, empty

◆ PrefixFilter() [2/2]

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

the empty filter for \( n \) keys, its bins at the load 0.95 when they are in, at least one bin

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

Member function documentation

◆ bins()

template<class T, class H = DefaultHash< T >>
std::size_t ADS::PrefixFilter< T, H >::bins ( void ) const
nodiscard

the bins, of 256 bits each

◆ bits()

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

the bits of the bins and of the spare

◆ capacity()

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

the keys that fit, the \( n \) of the constructor

◆ clear()

template<class T, class H = DefaultHash< T >>
void ADS::PrefixFilter< T, H >::clear ( void )

removes all the keys

◆ empty()

template<class T, class H = DefaultHash< T >>
bool ADS::PrefixFilter< T, H >::empty ( void ) const
nodiscard

whether no key is in

◆ expectedSpareSize()

template<class T, class H = DefaultHash< T >>
double ADS::PrefixFilter< T, H >::expectedSpareSize ( void ) const
nodiscard

the expected fingerprints sent to the spare when capacity() keys are in, \( \mathrm{E}[ X ] = n - m \, \mathrm{E}[ \min( B , 25 ) ] \)

◆ falsePositiveRate()

template<class T, class H = DefaultHash< T >>
double ADS::PrefixFilter< T, H >::falsePositiveRate ( void ) const
nodiscard

the expected false positives at the current load, the sum of the analysis of PrefixFilter.h over the loads \( j \) of a bin

◆ insert()

template<class T, class H = DefaultHash< T >>
bool ADS::PrefixFilter< T, H >::insert ( const T & x)

\( x \) into the filter by insertHash() of its hash, false (and nothing changed) if \( n \) keys are in

Postcondition
maybe( x ) if true

◆ insertHash()

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

the hash \( h \) of 64 bits, which must be random, into the filter, false (and nothing changed) if \( n \) keys are in

In pseudocode (Even, Even and Morrison), \( x_{\max} \) the largest mini-fingerprint of a full bin:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{insertHash}( h ) \cr 2 & \quad \textbf{if}\ n \text{ keys are in }\ \textbf{then return false} \cr 3 & \quad b \gets \lfloor h_1 m / 2^{32} \rfloor;\ x \gets \lfloor h_0 s / 2^{32} \rfloor \cr 4 & \quad \textbf{if}\ \text{the bin } b \text{ holds fewer than 25 } \ \textbf{then}\ \text{put } ( \lfloor x / 2^8 \rfloor , x \bmod 2^8 ) \text{ in its run} \cr 5 & \quad \textbf{else if}\ x \ge x_{\max}\ \textbf{then} \ \text{insert } s b + x \text{ into the spare} \cr 6 & \quad \textbf{else}\ \text{insert } s b + x_{\max} \text{ into the } \text{spare, and put } x \text{ in the place of } x_{\max} \cr 7 & \quad \textbf{if}\ \text{the bin was full }\ \textbf{then} \ \text{write the quotient of its maximum in the header} \cr 8 & \quad \textbf{return true} \end{array}} \]

◆ load()

template<class T, class H = DefaultHash< T >>
double ADS::PrefixFilter< T, H >::load ( void ) const
nodiscard

size() / ( 25 bins() ), at most about 0.95

◆ maybe()

template<class T, class H = DefaultHash< T >>
bool ADS::PrefixFilter< T, 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 H = DefaultHash< T >>
bool ADS::PrefixFilter< T, 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 (Even, Even and Morrison), the bound of a bin being its largest mini-fingerprint once it overflowed, and above every mini-fingerprint before:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{maybeHash}( h ) \cr 2 & \quad b \gets \lfloor h_1 m / 2^{32} \rfloor;\ x \gets \lfloor h_0 s / 2^{32} \rfloor \cr 3 & \quad q \gets \lfloor x / 2^8 \rfloor;\ r \gets x \bmod 2^8; \ H \gets \text{the header of the bin } b;\ E \gets \text{the} \text{ slots of its body that hold } r \cr 4 & \quad \textbf{if}\ E = \{ i \}\ \textbf{then}\ f \gets [ \text{the} \text{ bit } i + q \text{ of } H \text{ is 1, with } i \text{ ones} \text{ of } H \text{ below it} ] \cr 5 & \quad \textbf{else if}\ E \ne \emptyset\ \textbf{then}\ u \gets 2 H;\ z \gets \mathrm{select}_0( u , q );\ e \gets z + \text{the} \text{ ones of } u \text{ above } z \text{, up to its next 0} \cr 6 & \qquad f \gets [ E \cap [ z - q , e - q ) \ne \emptyset ] \cr 7 & \quad \textbf{else}\ f \gets \textbf{false} \cr 8 & \quad \textbf{if}\ f\ \textbf{then return true} \cr 9 & \quad \textbf{if}\ x > \text{the bound of the bin } b \ \textbf{then return}\ \text{the answer of the spare to } s b + x \cr 10 & \quad \textbf{return false} \end{array}} \]

◆ persist()

template<class T, class H = DefaultHash< T >>
template<class A>
void ADS::PrefixFilter< T, H >::persist ( A & a)

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

◆ persistTag()

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

the parameters of the layout, in a file

◆ size()

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

the keys in, with their repetitions

◆ spareSize()

template<class T, class H = DefaultHash< T >>
std::size_t ADS::PrefixFilter< T, H >::spareSize ( void ) const
nodiscard

the fingerprints sent to the spare

Member data documentation

◆ persistName

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

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


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