a minimal perfect hash function of a static set of keys by pilots
More...
#include <ADS/dictionary/MinimalPerfectHash.h>
|
| using | Key = T |
| | the type of the keys
|
|
| | 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 constexpr std::uint64_t | persistTag (void) |
| | the parameters of the layout, in a file
|
|
| static constexpr std::string_view | persistName = "MinimalPerfectHash" |
| | the name of the structure in a file [see Persistence.h]
|
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
◆ Key
template<class T, class H = DefaultHash< T >>
◆ MinimalPerfectHash() [1/2]
template<class T, class H = DefaultHash< T >>
◆ 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)
◆ bits()
template<class T, class H = DefaultHash< T >>
the bits of the function: the pilots, the free places and the sizes
◆ buckets()
template<class T, class H = DefaultHash< T >>
◆ empty()
template<class T, class H = DefaultHash< T >>
true if there are no keys
◆ operator()()
template<class T, class H = DefaultHash< T >>
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>
the members written to, or read from, the archive \( a \) [see Persistence.h]
◆ persistTag()
template<class T, class H = DefaultHash< T >>
|
|
inlinestaticnodiscardconstexpr |
the parameters of the layout, in a file
◆ size()
template<class T, class H = DefaultHash< T >>
the number \( n \) of keys
◆ trials()
template<class T, class H = DefaultHash< T >>
the seeds drawn by the build
◆ persistName
template<class T, class H = DefaultHash< T >>
The documentation for this class was generated from the following file: