|
| | OpenHashTable (std::size_t m, Probing probe, bool restructure=false, H h=H()) |
| | the empty table of size m with the given inspection, which restructures itself or not
|
| std::optional< V > | lookup (const K &k) const |
| | the value of the key \( k \), or nothing
|
| void | insert (const K &k, const V &v) |
| | associates the value \( v \) to the key \( k \); throws std::overflow_error if the inspection finds no place
|
| void | remove (const K &k) |
| | removes the key \( k \), if it is there, leaving a deleted place, by scan( k , false ) of lookup(); the table, if it restructures itself, halves below the load \( 1 / 8 \)
|
| bool | contains (const K &k) const |
| | true if the key \( k \) is there
|
| const K * | findKey (const K &k) const |
| | the address of the key \( k \), nil if absent, in \( O( 1 ) \) expected time: the find( x ) of a USet of Morin, which makes DictionarySet a USet [see SetInterfaces.h]; valid until the next change of the table
|
| std::size_t | size (void) const |
| | the number \( n \) of keys
|
| bool | empty (void) const |
| | true if there are no keys
|
| std::size_t | capacity (void) const |
| | the size \( m \) of the vector
|
| double | load (void) const |
| | the load factor \( n / m \)
|
| template<class F> |
| void | forEach (F &&f) const |
| | the foreach of the book: f( k , v ) on the pairs, place after place, \( O( m ) \) time
|
| Slot | slot (std::size_t i) const |
| | the state of the place \( i \)
|
| const K & | keyAt (std::size_t i) const |
| | the key in the place \( i \)
|
| std::size_t | probes (void) const |
| | the places examined by the last operation
|
| std::size_t | restructures (void) const |
| | the number of restructurings so far
|
| std::size_t | moved (void) const |
| | the number of pairs moved by the restructurings so far
|
| 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::OpenHashTable< K, V, H >
a hash table with open addressing
template<class K, class V, class H = std::hash< K >>
associates the value \( v \) to the key \( k \); throws std::overflow_error if the inspection finds no place
In pseudocode (sections 7.2.2 and 7.4), the table doubling when its full and deleted places pass \( m / 2 \), if it restructures itself:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{insert}( k , v ) \cr
2 & \quad j \gets \mathrm{scan}( k , \textbf{true} ) \cr
3 & \quad \textbf{if}\ T[ j ] \text{ is full with a key other than } k
\ \textbf{then}\ \text{throw an overflow}\quad \triangleright\ m
\text{ probes, no place} \cr
4 & \quad \textbf{if}\ T[ j ] \text{ is not full}\ \textbf{then}\ n
\gets n + 1 \cr
5 & \quad T[ j ] \gets ( k , v ) \text{, full} \cr
6 & \quad \textbf{if}\ m < 2 ( \text{the full places} +
\text{the deleted places} )\ \textbf{then}\ \text{rebuild on }
\mathrm{resized}( m ) \text{ places}
\end{array}}
\]
- Postcondition
- \( k \) is in the table
template<class K, class V, class H = std::hash< K >>
the value of the key \( k \), or nothing
In pseudocode (section 7.2.2), \( T[ 0 .. m - 1 ] \) the places; the scan of the book stops at the key, at a nil place or after \( m \) inspections, and for an insertion remembers the first deleted place:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{scan}( k , \mathit{insert} )\quad
\triangleright\ \text{the probes } H( k , 0 ) , H( k , 1 ) , \ldots
\cr
2 & \quad i \gets 0;\ j \gets H( k , 0 );\ d \gets \textbf{nil}\quad
\triangleright\ d \text{ the first deleted place met} \cr
3 & \quad \textbf{while}\ T[ j ] \text{ does not hold } k\ \textbf{and}
\ T[ j ] \text{ is not nil}\ \textbf{and}\ i < m\ \textbf{do} \cr
4 & \qquad \textbf{if}\ d = \textbf{nil}\ \textbf{and}\ T[ j ]
\text{ is deleted}\ \textbf{then}\ d \gets j \cr
5 & \qquad i \gets i + 1;\ j \gets H( k , i ) \cr
6 & \quad \textbf{if}\ \mathit{insert}\ \textbf{and}\ d \ne
\textbf{nil}\ \textbf{and}\ T[ j ] \text{ does not hold } k
\ \textbf{then return}\ d\quad \triangleright\ \text{reuse it} \cr
7 & \quad \textbf{return}\ j \cr
8 & \textbf{function}\ \mathrm{lookup}( k ) \cr
9 & \quad j \gets \mathrm{scan}( k , \textbf{false} ) \cr
10 & \quad \textbf{return}\ T[ j ].\mathit{value} \text{ if } T[ j ]
\text{ holds } k \text{, else } \textbf{nil}
\end{array}}
\]
template<class K, class V, class H = std::hash< K >>
removes the key \( k \), if it is there, leaving a deleted place, by scan( k , false ) of lookup(); the table, if it restructures itself, halves below the load \( 1 / 8 \)
- Postcondition
- \( k \) is not in the table