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

a minimal perfect hash function of a static set of keys by levels of fingerprints More...

#include <ADS/dictionary/FingerprintPerfectHash.h>

Public types

using Key = T
 the type of the keys

Public member functions

 FingerprintPerfectHash (void)
 the function of no key
 FingerprintPerfectHash (const std::vector< T > &keys, double gamma=2, std::uint64_t seed=1, H h=H())
 the function of the distinct keys, with \( \gamma \) bits per key in each level
std::size_t operator() (const T &k) const
 the value of \( k \), in \( [ 0 , n ) \); some value in it for a key out of \( S \)
std::size_t size (void) const
 the number \( n \) of keys
bool empty (void) const
 true if there are no keys
std::size_t bits (void) const
 the bits of the function: the levels, their ranks and their sizes
std::size_t levels (void) const
 the number of levels
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 = "FingerprintPerfectHash"
 the name of the structure in a file [see Persistence.h]

Detailed description

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

a minimal perfect hash function of a static set of keys by levels of fingerprints

Member typedef documentation

◆ Key

template<class T, class H = DefaultHash< T >>
using ADS::FingerprintPerfectHash< T, H >::Key = T

the type of the keys

Constructor and destructor documentation

◆ FingerprintPerfectHash() [1/2]

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

the function of no key

◆ FingerprintPerfectHash() [2/2]

template<class T, class H = DefaultHash< T >>
ADS::FingerprintPerfectHash< T, H >::FingerprintPerfectHash ( const std::vector< T > & keys,
double gamma = 2,
std::uint64_t seed = 1,
H h = H() )
explicit

the function of the distinct keys, with \( \gamma \) bits per key in each level

In pseudocode (Müller, Sanders, Schulze and Zhou, beyond the book), \( X \) the hashes of the keys still without a bit, \( A_i \) and \( C_i \) the bits of the level \( i \) and of its places met twice:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{build}( S , \gamma ) \cr 2 & \quad X \gets \{ \mathrm{base}( k ) : k \in S \};\ i \gets 0 \cr 3 & \quad \textbf{while}\ X \ne \emptyset\ \textbf{do} \cr 4 & \qquad \textbf{if}\ i = 64\ \textbf{then throw}\ \text{(too many} \text{ levels, or two keys of one hash)} \cr 5 & \qquad m_i \gets \lceil \gamma |X| \rceil \text{, rounded up to } \text{512};\ A_i , C_i \gets m_i \text{ bits } 0 \cr 6 & \qquad \textbf{foreach}\ x \in X\ \textbf{do} \cr 7 & \qquad\quad p \gets h_i( x );\ C_i[ p ] \gets C_i[ p ] \lor A_i[ p ]; \ A_i[ p ] \gets 1 \cr 8 & \qquad A_i \gets A_i \land \lnot C_i\quad \triangleright\ \text{a } \text{word at a time} \cr 9 & \qquad X \gets \{ x \in X : C_i[ h_i( x ) ] = 1 \};\ i \gets i + 1 \cr 10 & \quad \text{the count of the 1s before each block of 512 bits} \end{array}} \]

Precondition
the keys are distinct (an audit) and fewer than \( 2^{32} \), \( \gamma \ge 1 \)
Postcondition
the keys are mapped onto \( \{ 0 , \ldots , n - 1 \} \) (an audit)

Member function documentation

◆ bits()

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

the bits of the function: the levels, their ranks and their sizes

◆ empty()

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

true if there are no keys

◆ levels()

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

the number of levels

◆ operator()()

template<class T, class H = DefaultHash< T >>
std::size_t ADS::FingerprintPerfectHash< T, H >::operator() ( const T & k) const
nodiscard

the value of \( k \), in \( [ 0 , n ) \); some value in it for a key out of \( S \)

In pseudocode (beyond the book), \( L \) the levels one after another, \( a_i \) the first bit of the level \( i \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{value}( k ) \cr 2 & \quad x \gets \mathrm{base}( k ) \cr 3 & \quad \textbf{for}\ i \gets 0\ \textbf{to}\ \text{the last level} \ \textbf{do} \cr 4 & \qquad g \gets a_i + h_i( x ) \cr 5 & \qquad \textbf{if}\ L[ g ] = 1\ \textbf{then return} \ \mathrm{rank}( g )\quad \triangleright\ \text{the 1s before } g \cr 6 & \quad \textbf{return}\ \text{a value in } [ 0 , n ) \text{ from } x\quad \triangleright\ k \notin S \end{array}} \]

Precondition
size() \( \ge 1 \)

◆ persist()

template<class T, class H = DefaultHash< T >>
template<class A>
void ADS::FingerprintPerfectHash< 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::FingerprintPerfectHash< 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::FingerprintPerfectHash< T, H >::size ( void ) const
nodiscard

the number \( n \) of keys

Member data documentation

◆ persistName

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

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


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