a minimal perfect hash function of a static set of keys by levels of fingerprints
More...
#include <ADS/dictionary/FingerprintPerfectHash.h>
|
| using | Key = T |
| | the type of the keys
|
|
| | 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 constexpr std::uint64_t | persistTag (void) |
| | the parameters of the layout, in a file
|
|
| static constexpr std::string_view | persistName = "FingerprintPerfectHash" |
| | the name of the structure in a file [see Persistence.h]
|
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
◆ Key
template<class T, class H = DefaultHash< T >>
◆ FingerprintPerfectHash() [1/2]
template<class T, class H = DefaultHash< T >>
◆ 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)
◆ bits()
template<class T, class H = DefaultHash< T >>
the bits of the function: the levels, their ranks and their sizes
◆ empty()
template<class T, class H = DefaultHash< T >>
true if there are no keys
◆ levels()
template<class T, class H = DefaultHash< T >>
◆ 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 (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>
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
◆ persistName
template<class T, class H = DefaultHash< T >>
The documentation for this class was generated from the following file: