ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::CoalescedHashTable< K, V, H > Class Template Reference

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

Detailed description

template<class K, class V, class H = std::hash< K >>
class ADS::CoalescedHashTable< K, V, H >

a hash table with coalesced lists in the table and a cellar

Member typedef documentation

◆ const_iterator

template<class K, class V, class H = std::hash< K >>
using ADS::CoalescedHashTable< K, V, H >::const_iterator = SlotIterator< CoalescedHashTable , Places >

the iterator on the items, constant

◆ const_reference

template<class K, class V, class H = std::hash< K >>
using ADS::CoalescedHashTable< K, V, H >::const_reference = PairRef< const K & , const V & >

a constant reference to an item

◆ difference_type

template<class K, class V, class H = std::hash< K >>
using ADS::CoalescedHashTable< K, V, H >::difference_type = std::ptrdiff_t

the type of the distances between two iterators

◆ iterator

template<class K, class V, class H = std::hash< K >>
using ADS::CoalescedHashTable< K, V, H >::iterator = const_iterator

the iterator on the items

◆ key_type

template<class K, class V, class H = std::hash< K >>
using ADS::CoalescedHashTable< K, V, H >::key_type = K

the type of the keys

◆ mapped_type

template<class K, class V, class H = std::hash< K >>
using ADS::CoalescedHashTable< K, V, H >::mapped_type = V

the type of the values

◆ reference

template<class K, class V, class H = std::hash< K >>
using ADS::CoalescedHashTable< K, V, H >::reference = PairRef< const K & , const V & >

a reference to an item

◆ size_type

template<class K, class V, class H = std::hash< K >>
using ADS::CoalescedHashTable< K, V, H >::size_type = std::size_t

the type of the sizes

◆ value_type

template<class K, class V, class H = std::hash< K >>
using ADS::CoalescedHashTable< K, V, H >::value_type = std::pair< K , V >

the type of the items, for the standard library

Constructor and destructor documentation

◆ CoalescedHashTable()

template<class K, class V, class H = std::hash< K >>
ADS::CoalescedHashTable< K, V, H >::CoalescedHashTable ( std::size_t m,
std::size_t cellar = 0,
H h = H() )
explicit

a table of \( m \) places addressed by the hash and of cellar more

Precondition
\( m \ge 1 \)

Member function documentation

◆ begin()

template<class K, class V, class H = std::hash< K >>
const_iterator ADS::CoalescedHashTable< K, V, H >::begin ( void ) const
inlinenodiscard

the iterator on the first item

◆ cbegin()

template<class K, class V, class H = std::hash< K >>
const_iterator ADS::CoalescedHashTable< K, V, H >::cbegin ( void ) const
inlinenodiscard

the constant iterator on the first item

◆ cend()

template<class K, class V, class H = std::hash< K >>
const_iterator ADS::CoalescedHashTable< K, V, H >::cend ( void ) const
inlinenodiscard

the constant iterator past the last item

◆ end()

template<class K, class V, class H = std::hash< K >>
const_iterator ADS::CoalescedHashTable< K, V, H >::end ( void ) const
inlinenodiscard

the iterator past the last item

◆ insert()

template<class K, class V, class H = std::hash< K >>
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}} \]

Precondition
\( k \) is there, or the table is not full
Postcondition
\( k \) has the value \( v \)

◆ lookup()

template<class K, class V, class H = std::hash< K >>
std::optional< V > ADS::CoalescedHashTable< K, V, H >::lookup ( const K & k) const
nodiscard

the value of the key \( k \), or nothing, along the list of the place \( h( k ) \bmod m \)

◆ probes()

template<class K, class V, class H = std::hash< K >>
std::size_t ADS::CoalescedHashTable< K, V, H >::probes ( void ) const
nodiscard

the places examined by the last lookup() or insert()

◆ size()

template<class K, class V, class H = std::hash< K >>
std::size_t ADS::CoalescedHashTable< K, V, H >::size ( void ) const
nodiscard

the number of keys


The documentation for this class was generated from the following file: