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

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

#include <ADS/dictionary/MinimalPerfectHash.h>

Public types

using Key = T
 the type of the keys

Public member functions

 MinimalPerfectHash (void)
 the function of no key
 MinimalPerfectHash (const std::vector< T > &keys, double lambda=5, double alpha=0.99, std::uint64_t seed=1, H h=H())
 the function of the distinct keys, with \( \lambda \) keys per bucket on average and the load \( \alpha \) of the table
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 pilots, the free places and the sizes
std::size_t buckets (void) const
 the number of buckets
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 = "MinimalPerfectHash"
 the name of the structure in a file [see Persistence.h]

Detailed description

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

a minimal perfect hash function of a static set of keys by pilots

Member typedef documentation

◆ Key

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

the type of the keys

Constructor and destructor documentation

◆ MinimalPerfectHash() [1/2]

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

the function of no key

◆ MinimalPerfectHash() [2/2]

template<class T, class H = DefaultHash< T >>
ADS::MinimalPerfectHash< T, H >::MinimalPerfectHash ( const std::vector< T > & keys,
double lambda = 5,
double alpha = 0.99,
std::uint64_t seed = 1,
H h = H() )
explicit

the function of the distinct keys, with \( \lambda \) keys per bucket on average and the load \( \alpha \) of the table

In pseudocode (PTHash of Pibiri and Trani, beyond the book), \( B_b \) the second hashes of the keys of the bucket \( b \) and \( p( h' , k ) \) the place of \( h' \) with the pilot \( k \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{build}( S , \lambda , \alpha ) \cr 2 & \quad \text{group the keys by bucket, by a counting sort} \cr 3 & \quad \textbf{foreach}\ b \text{ by decreasing } |B_b|\ \textbf{do} \cr 4 & \qquad k \gets 0 \cr 5 & \qquad \textbf{while}\ \text{the places } p( h' , k ) \text{ of } B_b \text{ are not free and distinct}\ \textbf{do}\ k \gets k + 1 \cr 6 & \qquad k_b \gets k;\ \text{take the places } p( h' , k ) \cr 7 & \quad \text{map each place } p \ge n \text{ taken to a free place } \text{below } n \end{array}} \]

A seed is drawn again if two keys of a bucket have the same hashes or a bucket tries \( 2^{24} \) pilots.

Precondition
the keys are distinct (an audit) and fewer than \( 2^{32} \), \( \lambda \ge 1 \) and \( 0.5 \le \alpha \le 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::MinimalPerfectHash< T, H >::bits ( void ) const
nodiscard

the bits of the function: the pilots, the free places and the sizes

◆ buckets()

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

the number of buckets

◆ empty()

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

true if there are no keys

◆ operator()()

template<class T, class H = DefaultHash< T >>
std::size_t ADS::MinimalPerfectHash< 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 (PTHash, beyond the book), \( F \) the table of the free places below \( n \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{value}( k ) \cr 2 & \quad ( h , h' ) \gets \text{the two hashes of } k \cr 3 & \quad p \gets p( h' , k_{b( h )} )\quad \triangleright\ \text{one } \text{access, the pilot} \cr 4 & \quad \textbf{if}\ p < n\ \textbf{then return}\ p\ \textbf{else return}\ F[ p - n ] \end{array}} \]

Precondition
size() \( \ge 1 \)

◆ persist()

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

the number \( n \) of keys

◆ trials()

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

the seeds drawn by the build

Member data documentation

◆ persistName

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

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


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