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

a DICTIONARY on \( d \) tables of lists, a key in the shortest of its \( d \) lists More...

#include <ADS/dictionary/UniversalHashing.h>

Classes

class  const_iterator
 the iterator on the pairs, table after table and list after list More...

Public types

using Key = K
 the type of the keys
using Value = V
 the type of the values
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 = reference
 a constant reference to an item
using iterator = const_iterator
 the iterator on the items

Public member functions

 DLeftHashTable (std::size_t m, int d, std::uint64_t seed=1, H h=H())
 \( d \) tables of \( w \) lists each, \( w = \max\{ 1 , \lfloor m / d \rfloor \} \)
std::optional< V > lookup (const K &k) const
 the value of the key \( k \), or nothing, from its \( d \) lists
void insert (const K &k, const V &v)
 associates the value \( v \) to the key \( k \)
void remove (const K &k)
 removes the key \( k \), if it is there, from its list
bool contains (const K &k) const
 true if the key \( k \) is there
std::size_t size (void) const
 the number of keys
std::size_t maxLoad (void) const
 the length of the longest list
int tables (void) const
 the number of tables
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::DLeftHashTable< K, V, H >

a DICTIONARY on \( d \) tables of lists, a key in the shortest of its \( d \) lists

Member typedef documentation

◆ const_reference

template<class K, class V, class H = std::hash< K >>
using ADS::DLeftHashTable< K, V, H >::const_reference = reference

a constant reference to an item

◆ difference_type

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

the iterator on the items

◆ Key

template<class K, class V, class H = std::hash< K >>
using ADS::DLeftHashTable< K, V, H >::Key = K

the type of the keys

◆ key_type

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

the type of the values

◆ reference

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

the type of the sizes

◆ Value

template<class K, class V, class H = std::hash< K >>
using ADS::DLeftHashTable< K, V, H >::Value = V

the type of the values

◆ value_type

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

the type of the items, for the standard library

Constructor and destructor documentation

◆ DLeftHashTable()

template<class K, class V, class H = std::hash< K >>
ADS::DLeftHashTable< K, V, H >::DLeftHashTable ( std::size_t m,
int d,
std::uint64_t seed = 1,
H h = H() )

\( d \) tables of \( w \) lists each, \( w = \max\{ 1 , \lfloor m / d \rfloor \} \)

Precondition
\( m \ge 1 \) and \( d \ge 1 \)

Member function documentation

◆ begin()

template<class K, class V, class H = std::hash< K >>
const_iterator ADS::DLeftHashTable< 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::DLeftHashTable< 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::DLeftHashTable< K, V, H >::cend ( void ) const
inlinenodiscard

the constant iterator past the last item

◆ contains()

template<class K, class V, class H = std::hash< K >>
bool ADS::DLeftHashTable< K, V, H >::contains ( const K & k) const
nodiscard

true if the key \( k \) is there

◆ end()

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

associates the value \( v \) to the key \( k \)

In pseudocode (the d-left hashing of Vöcking, beyond the book), \( L_i( k ) \) the list of \( k \) in the table \( i \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{insert}( k , v ) \cr 2 & \quad \textbf{if}\ k \text{ is in some } L_i( k )\ \textbf{then} \ \text{give it the value } v;\ \textbf{return} \cr 3 & \quad j \gets 0 \cr 4 & \quad \textbf{for}\ i \gets 1\ \textbf{to}\ d - 1\ \textbf{do} \ \textbf{if}\ |L_i( k )| < |L_j( k )|\ \textbf{then}\ j \gets i \cr 5 & \quad \text{append } ( k , v ) \text{ to } L_j( k )\quad \triangleright\ \text{the shortest, the leftmost on a tie} \end{array}} \]

Postcondition
\( k \) has the value \( v \)

◆ lookup()

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

the value of the key \( k \), or nothing, from its \( d \) lists

◆ maxLoad()

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

the length of the longest list

◆ remove()

template<class K, class V, class H = std::hash< K >>
void ADS::DLeftHashTable< K, V, H >::remove ( const K & k)

removes the key \( k \), if it is there, from its list

Postcondition
\( k \) is not there

◆ size()

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

the number of keys

◆ tables()

template<class K, class V, class H = std::hash< K >>
int ADS::DLeftHashTable< K, V, H >::tables ( void ) const
nodiscard

the number of tables


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