|
ADS
Algorithms and Data Structures
|
a hash table with coalesced lists in the table and a cellar More...
#include <ADS/dictionary/KnuthHashing.h>
Classes | |
| struct | Places |
| the places of the table, for SlotIterator More... | |
Public types | |
| using | value_type = std::pair< K , V > |
| the type of the items, for the standard library | |
| using | key_type = K |
| the type of the keys | |
| using | mapped_type = V |
| the type of the values | |
| using | size_type = std::size_t |
| the type of the sizes | |
| using | difference_type = std::ptrdiff_t |
| the type of the distances between two iterators | |
| using | reference = PairRef< const K & , const V & > |
| a reference to an item | |
| using | const_reference = PairRef< const K & , const V & > |
| a constant reference to an item | |
| using | const_iterator = SlotIterator< CoalescedHashTable , Places > |
| the iterator on the items, constant | |
| using | iterator = const_iterator |
| the iterator on the items | |
Public member functions | |
| CoalescedHashTable (std::size_t m, std::size_t cellar=0, H h=H()) | |
| a table of \( m \) places addressed by the hash and of cellar more | |
| std::optional< V > | lookup (const K &k) const |
| the value of the key \( k \), or nothing, along the list of the place \( h( k ) \bmod m \) | |
| 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() or insert() | |
| 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 | |
a hash table with coalesced lists in the table and a cellar
| using ADS::CoalescedHashTable< K, V, H >::const_iterator = SlotIterator< CoalescedHashTable , Places > |
the iterator on the items, constant
| using ADS::CoalescedHashTable< K, V, H >::const_reference = PairRef< const K & , const V & > |
a constant reference to an item
| using ADS::CoalescedHashTable< K, V, H >::difference_type = std::ptrdiff_t |
the type of the distances between two iterators
| using ADS::CoalescedHashTable< K, V, H >::iterator = const_iterator |
the iterator on the items
| using ADS::CoalescedHashTable< K, V, H >::key_type = K |
the type of the keys
| using ADS::CoalescedHashTable< K, V, H >::mapped_type = V |
the type of the values
| using ADS::CoalescedHashTable< K, V, H >::reference = PairRef< const K & , const V & > |
a reference to an item
| using ADS::CoalescedHashTable< K, V, H >::size_type = std::size_t |
the type of the sizes
| using ADS::CoalescedHashTable< K, V, H >::value_type = std::pair< K , V > |
the type of the items, for the standard library
|
explicit |
a table of \( m \) places addressed by the hash and of cellar more
|
inlinenodiscard |
the iterator on the first item
|
inlinenodiscard |
the constant iterator on the first item
|
inlinenodiscard |
the constant iterator past the last item
|
inlinenodiscard |
the iterator past the last item
| void ADS::CoalescedHashTable< K, V, H >::insert | ( | const K & | k, |
| const V & | v ) |
associates \( v \) to \( k \)
In pseudocode (Algorithm 6.4C of TAOCP, beyond the book), \( T \) the places, the cellar last, and \( r \) a pointer that only goes down, below which the empty places are:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{insert}( k , v ) \cr 2 & \quad i \gets h( k ) \bmod m \cr 3 & \quad \textbf{if}\ T[ i ] \text{ is used }\ \textbf{then} \cr 4 & \qquad \textbf{loop} \cr 5 & \qquad\quad \textbf{if}\ T[ i ].\mathit{key} = k\ \textbf{then}\ T[ i ].\mathit{value} \gets v;\ \textbf{return} \cr 6 & \qquad\quad \textbf{if}\ T[ i ].\mathit{link} = \textbf{nil} \ \textbf{then}\ \textbf{break}\ \textbf{else}\ i \gets T[ i ].\mathit{link} \cr 7 & \qquad \textbf{repeat}\ r \gets r - 1\ \textbf{until}\ T[ r ] \text{ is empty} \cr 8 & \qquad T[ i ].\mathit{link} \gets r;\ i \gets r\quad \triangleright \ \text{linked at the end of the list} \cr 9 & \quad T[ i ] \gets ( k , v , \textbf{nil} ) \end{array}} \]
|
nodiscard |
the value of the key \( k \), or nothing, along the list of the place \( h( k ) \bmod m \)
|
nodiscard |
|
nodiscard |
the number of keys