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

a static filter of the keys of type T with fingerprints of type F, 3 places per key in 3 consecutive segments More...

#include <ADS/set/BinaryFuseFilter.h>

Public member functions

 BinaryFuseFilter (void)
 the filter of no key
 BinaryFuseFilter (const std::vector< T > &keys, std::uint64_t seed=1, H h=H())
 the filter of the keys, which may repeat
bool maybe (const T &x) const
 whether \( x \) may be in the set: true for every key of the set, and for any other with probability about \( 2^{-b} \), \( b \) the bits of F
std::size_t size (void) const
 the keys of the build, the repeated ones once each
bool empty (void) const
 whether the filter has no key
std::size_t bits (void) const
 the bits of the fingerprints
std::size_t trials (void) const
 the seeds drawn by the build
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 = "BinaryFuseFilter"
 the name of the structure in a file [see Persistence.h]
static constexpr std::uint32_t persistVersion = 2
 the version of the layout in a file: 2, whose bit 63 of the trials says that the fingerprints are by a product; a filter read from a file of the version 1, where it is clear, keeps those of the bits of \( h \oplus ( h \gg 32 ) \)
static constexpr std::uint32_t persistOldestVersion = 1
 the oldest version read: 1, whose filters keep their fingerprints

Detailed description

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
requires ( std::is_unsigned_v< F > && ( sizeof( F ) <= 4 ) )
class ADS::BinaryFuseFilter< T, F, H >

a static filter of the keys of type T with fingerprints of type F, 3 places per key in 3 consecutive segments

Constructor and destructor documentation

◆ BinaryFuseFilter() [1/2]

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

the filter of no key

◆ BinaryFuseFilter() [2/2]

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
ADS::BinaryFuseFilter< T, F, H >::BinaryFuseFilter ( const std::vector< T > & keys,
std::uint64_t seed = 1,
H h = H() )
explicit

the filter of the keys, which may repeat

In pseudocode (Graf and Lemire), \( c[ p ] \) the keys of the place \( p \), \( x[ p ] \) the XOR of their hashes and \( s[ p ] \) the XOR of the indices by which they reach it:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{build}( K ) \cr 2 & \quad \textbf{repeat} \cr 3 & \qquad \text{draw a seed};\ H \gets \text{the hashes of } K \text{ mixed by it, sorted by the segment of } h_0 \cr 4 & \qquad \textbf{foreach}\ h \in H ,\ i \in \{ 0 , 1 , 2 \} \ \textbf{do}\ c[ h_i ] \gets c[ h_i ] + 1;\ x[ h_i ] \gets x[ h_i ] \oplus h;\ s[ h_i ] \gets s[ h_i ] \oplus i \cr & \qquad\quad \triangleright\ \text{the seed fails if a place reaches} \text{ 63 keys} \cr 5 & \qquad Q \gets \text{the places } p \text{ with } c[ p ] = 1;\ P \gets \text{an empty stack} \cr 6 & \qquad \textbf{while}\ Q \ne \emptyset\ \textbf{do} \cr 7 & \qquad\quad p \gets \text{a place of } Q;\ \textbf{if}\ c[ p ] \ne 1\ \textbf{then continue} \cr 8 & \qquad\quad h \gets x[ p ];\ i \gets s[ p ]; \ \mathrm{push}( P , ( h , i ) ) \cr 9 & \qquad\quad \textbf{foreach}\ j \ne i\ \textbf{do}\ \text{remove } h \text{ from } h_j \text{, adding } h_j \text{ to } Q \text{ if it } \text{has one key left} \cr 10 & \qquad \textbf{if}\ \text{not all the keys are in } P \ \textbf{then}\ \text{remove from } K \text{ the keys of equal} \text{ hashes, once, and size } F \text{ again} \cr 11 & \quad \textbf{until}\ \text{all the keys are in } P \cr 12 & \quad \textbf{while}\ P \ne \emptyset\ \textbf{do} \cr 13 & \qquad ( h , i ) \gets \mathrm{pop}( P );\ F[ h_i ] \gets f( h ) \oplus F[ h_0 ] \oplus F[ h_1 ] \oplus F[ h_2 ] \text{ with } F[ h_i ] = 0 \end{array}} \]

Precondition
fewer than \( 2^{31} \) keys
Postcondition
every key is maybe there (an audit)

Member function documentation

◆ bits()

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

the bits of the fingerprints

◆ empty()

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

whether the filter has no key

◆ maybe()

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

whether \( x \) may be in the set: true for every key of the set, and for any other with probability about \( 2^{-b} \), \( b \) the bits of F

In pseudocode (Graf and Lemire):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{maybe}( x ) \cr 2 & \quad h \gets \text{the hash of } x \text{ under the seed} \cr 3 & \quad \textbf{return}\ F[ h_0 ] \oplus F[ h_1 ] \oplus F[ h_2 ] = f( h ) \end{array}} \]

◆ persist()

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
template<class A>
void ADS::BinaryFuseFilter< 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::BinaryFuseFilter< T, F, H >::persistTag ( void )
inlinestaticnodiscardconstexpr

the parameters of the layout, in a file

◆ size()

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

the keys of the build, the repeated ones once each

◆ trials()

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

the seeds drawn by the build

Member data documentation

◆ persistName

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

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

◆ persistOldestVersion

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
std::uint32_t ADS::BinaryFuseFilter< T, F, H >::persistOldestVersion = 1
staticconstexpr

the oldest version read: 1, whose filters keep their fingerprints

◆ persistVersion

template<class T, class F = std::uint8_t, class H = DefaultHash< T >>
std::uint32_t ADS::BinaryFuseFilter< T, F, H >::persistVersion = 2
staticconstexpr

the version of the layout in a file: 2, whose bit 63 of the trials says that the fingerprints are by a product; a filter read from a file of the version 1, where it is clear, keeps those of the bits of \( h \oplus ( h \gg 32 ) \)


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