a static SET of integers on the two-level perfect hashing
More...
#include <ADS/dictionary/PerfectHashing.h>
|
| | PerfectHashTable (const std::vector< std::uint64_t > &S, std::uint64_t seed=1) |
| | the table of the keys of \( S \)
|
| bool | contains (std::uint64_t k) const |
| | whether \( k \) is in \( S \), any \( k \), in \( O( 1 ) \) time in the worst case: the key in the place \( h_j( k ) \) of the table \( j = h( k ) \) compared with \( k \)
|
| std::size_t | size (void) const |
| | the number of keys
|
| std::size_t | space (void) const |
| | the places of the second level, \( \sum_j n_j^2 \)
|
| std::size_t | trials (void) const |
| | the functions drawn by the build, of both levels
|
| template<class A> |
| void | persist (A &a) |
| | the members written to, or read from, the archive \( a \) [see Persistence.h]
|
| const_iterator | begin (void) const |
| | the iterator on the first item
|
| const_iterator | end (void) const |
| | the iterator past the last item
|
| const_iterator | cbegin (void) const |
| | the constant iterator on the first item
|
| const_iterator | cend (void) const |
| | the constant iterator past the last item
|
|
| static constexpr std::string_view | persistName = "PerfectHashTable" |
| | the name of the structure in a file [see Persistence.h]
|
a static SET of integers on the two-level perfect hashing
◆ const_iterator
the iterator on the items, constant
◆ const_reference
a constant reference to an item
◆ difference_type
the type of the distances between two iterators
◆ iterator
the iterator on the items
◆ Key
◆ reference
◆ size_type
◆ value_type
the type of the items, for the standard library
◆ PerfectHashTable()
| ADS::PerfectHashTable::PerfectHashTable |
( |
const std::vector< std::uint64_t > & | S, |
|
|
std::uint64_t | seed = 1 ) |
|
explicit |
the table of the keys of \( S \)
In pseudocode (Fredman, Komlós and Szemerédi, chapter 8 of Ferragina), \( n_j \) the keys of \( S \) with \( h( k ) = j \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{build}( S ) \cr
2 & \quad \textbf{repeat}\ h \gets \text{a function of } H_{p,n}
\text{ at random}\ \textbf{until}\ \sum_j n_j^2 < 4 n \cr
3 & \quad \textbf{for}\ j \gets 0\ \textbf{to}\ n - 1\ \textbf{with}\ n_j
> 0\ \textbf{do} \cr
4 & \qquad \textbf{repeat}\ h_j \gets \text{a function of } H_{p,n_j^2}
\text{ at random} \cr
5 & \qquad \textbf{until}\ h_j \text{ has no collision on the keys of }
\text{the list } j \cr
6 & \qquad \text{put each key } k \text{ of the list in the place } h_j( k
) \text{ of the table } j
\end{array}}
\]
Each table of the second level is found after fewer than 2 trials on average, since its expected collisions are below \( 1 / 2 \); the first level stops when \( \sum_j n_j^2 < 4 n \), which by the inequality of Markov on \( \sum_j n_j^2 - n \ge 0 \), of expectation below \( n \), happens with probability above \( 2 / 3 \) (a threshold of \( 2 n \) would guarantee only \( 1 / n \)).
- Precondition
- the keys are distinct (an audit) and below \( 2^{61} - 1 \)
- Postcondition
- each key of \( S \) is there (an audit), and \( \sum_j n_j^2 < 4 n \)
◆ begin()
the iterator on the first item
◆ cbegin()
the constant iterator on the first item
◆ cend()
the constant iterator past the last item
◆ contains()
| bool ADS::PerfectHashTable::contains |
( |
std::uint64_t | k | ) |
const |
|
nodiscard |
whether \( k \) is in \( S \), any \( k \), in \( O( 1 ) \) time in the worst case: the key in the place \( h_j( k ) \) of the table \( j = h( k ) \) compared with \( k \)
In pseudocode (Fredman, Komlós and Szemerédi, beyond the book), \( T_j \) the table of \( n_j^2 \) places of the list \( j \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{contains}( k ) \cr
2 & \quad j \gets h( k ) \cr
3 & \quad \textbf{return}\ n_j > 0\ \textbf{and}\ T_j[ h_j( k ) ] = k
\end{array}}
\]
◆ end()
the iterator past the last item
◆ persist()
template<class A>
| void ADS::PerfectHashTable::persist |
( |
A & | a | ) |
|
the members written to, or read from, the archive \( a \) [see Persistence.h]
◆ persistEmpty()
◆ size()
| std::size_t ADS::PerfectHashTable::size |
( |
void | | ) |
const |
|
nodiscard |
◆ space()
| std::size_t ADS::PerfectHashTable::space |
( |
void | | ) |
const |
|
nodiscard |
the places of the second level, \( \sum_j n_j^2 \)
◆ trials()
| std::size_t ADS::PerfectHashTable::trials |
( |
void | | ) |
const |
|
nodiscard |
the functions drawn by the build, of both levels
◆ persistName
| std::string_view ADS::PerfectHashTable::persistName = "PerfectHashTable" |
|
staticconstexpr |
The documentation for this class was generated from the following file: