|
| | BrentHashTable (std::size_t m, H h=H()) |
| | a table of \( m \) places
|
| std::optional< V > | lookup (const K &k) const |
| | the value of the key \( k \), or nothing, along the places \( \mathrm{at}( k , 0 ) , \mathrm{at}( k , 1 ) , \ldots \) of its inspection up to an empty one
|
| void | insert (const K &k, const V &v) |
| | associates \( v \) to \( k \)
|
| std::size_t | size (void) const |
| | the number of keys
|
| std::size_t | probes (void) const |
| | the places examined by the last lookup()
|
| 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
|
template<class K, class V, class H = std::hash< K >>
class ADS::BrentHashTable< K, V, H >
a hash table with double hashing and the insertion of Brent
template<class K, class V, class H = std::hash< K >>
associates \( v \) to \( k \)
In pseudocode (the variation of Brent, exercise 6.4-49 of TAOCP, beyond the book), \( \mathrm{at}( x , i ) \) the place \( i \) of the inspection of \( x \) and \( i_y \) the index of the key \( y \) in its own inspection; the key at the place \( j \) of the inspection of \( k \) moves \( s - j \) places on in its own:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{insert}( k , v ) \cr
2 & \quad \textbf{if}\ k \text{ is there }\ \textbf{then}\ \text{give it }
\text{the value } v;\ \textbf{return} \cr
3 & \quad \textbf{for}\ s \gets 0\ \textbf{to}\ m - 1\ \textbf{do} \cr
4 & \qquad \textbf{for}\ j \gets 0\ \textbf{to}\ s\ \textbf{do} \cr
5 & \qquad\quad p \gets \mathrm{at}( k , j ) \cr
6 & \qquad\quad \textbf{if}\ j = s\ \textbf{then} \cr
7 & \qquad\qquad \textbf{if}\ T[ p ] \text{ is empty }\ \textbf{then}\ T[
p ] \gets ( k , v );\ \textbf{return} \cr
8 & \qquad\quad \textbf{else} \cr
9 & \qquad\qquad y \gets T[ p ].\mathit{key};\ q \gets \mathrm{at}( y ,
i_y + s - j ) \cr
10 & \qquad\qquad \textbf{if}\ T[ q ] \text{ is empty }\ \textbf{then}\ T[
q ] \gets T[ p ];\ T[ p ] \gets ( k , v );\ \textbf{return}
\end{array}}
\]
- Precondition
- \( k \) is there, or the table is not full
- Postcondition
- \( k \) has the value \( v \)
template<class K, class V, class H = std::hash< K >>
the value of the key \( k \), or nothing, along the places \( \mathrm{at}( k , 0 ) , \mathrm{at}( k , 1 ) , \ldots \) of its inspection up to an empty one