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

a hash table with double hashing and the insertion of Brent 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 = const std::pair< K , V > &
 a reference to an item
using const_reference = const std::pair< K , V > &
 a constant reference to an item
using const_iterator = SlotIterator< BrentHashTable , Places >
 the iterator on the items, constant
using iterator = const_iterator
 the iterator on the items

Public member functions

 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

Detailed description

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

Member typedef documentation

◆ const_iterator

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

the iterator on the items, constant

◆ const_reference

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

a constant reference to an item

◆ difference_type

template<class K, class V, class H = std::hash< K >>
using ADS::BrentHashTable< 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::BrentHashTable< 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::BrentHashTable< 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::BrentHashTable< K, V, H >::mapped_type = V

the type of the values

◆ reference

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

a reference to an item

◆ size_type

template<class K, class V, class H = std::hash< K >>
using ADS::BrentHashTable< 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::BrentHashTable< K, V, H >::value_type = std::pair< K , V >

the type of the items, for the standard library

Constructor and destructor documentation

◆ BrentHashTable()

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

a table of \( m \) places

Precondition
\( m \ge 2 \) is prime

Member function documentation

◆ begin()

template<class K, class V, class H = std::hash< K >>
const_iterator ADS::BrentHashTable< 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::BrentHashTable< 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::BrentHashTable< 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::BrentHashTable< 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::BrentHashTable< K, V, H >::insert ( const K & k,
const V & v )

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 \)

◆ lookup()

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

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

◆ probes()

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

the places examined by the last lookup()

◆ size()

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

the number of keys


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