ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::HashMultiset< T, H > Class Template Reference

a multiset on a hash table, a counter of occurrences per item: the insertion of a new item sets it to 1, of an item already there adds 1, the removal subtracts 1 and removes the item at 0 (exercise 8.10) More...

#include <ADS/set/HashMultiset.h>

Public types

using Item = T
 the type of the items
using value_type = std::pair< T , std::size_t >
 a pair of an item and its occurrences
using const_iterator
 the iterator of the table of the counters, constant
using iterator = const_iterator
 the same, constant

Public member functions

 HashMultiset (void)
 the empty multiset
std::size_t size (void) const
 the number of items, each counted as many times as it occurs
std::size_t distinct (void) const
 the number of distinct items
bool empty (void) const
 whether the multiset has no item
bool contains (const T &x) const
 whether \( x \) occurs at least once
std::size_t count (const T &x) const
 the occurrences of \( x \), 0 if none
void insert (const T &x)
 one occurrence of \( x \) more
void remove (const T &x)
 one occurrence of \( x \) less, if there is one
template<class F>
void forEach (F &&f) const
 f( x , c ) on the distinct items and their occurrences
const_iterator begin (void) const
 the iterator on the first pair
const_iterator end (void) const
 the iterator past the last pair
const_iterator cbegin (void) const
 as begin()
const_iterator cend (void) const
 as end()

Detailed description

template<class T, class H = std::hash< T >>
class ADS::HashMultiset< T, H >

a multiset on a hash table, a counter of occurrences per item: the insertion of a new item sets it to 1, of an item already there adds 1, the removal subtracts 1 and removes the item at 0 (exercise 8.10)

Member typedef documentation

◆ const_iterator

template<class T, class H = std::hash< T >>
using ADS::HashMultiset< T, H >::const_iterator
Initial value:
typename ChainedHashTable< T , std::size_t , Chain::FRONT ,
a hash table with lists of overflow
Definition ChainedHashTable.h:103
typename detail::AllocVector< A, std::pair< K, V > >::const_iterator const_iterator
the iterator on the items, constant
Definition DenseHashMap.h:408
@ FRONT
a new key at the head, nothing moves
Definition ChainedHashTable.h:93

the iterator of the table of the counters, constant

◆ Item

template<class T, class H = std::hash< T >>
using ADS::HashMultiset< T, H >::Item = T

the type of the items

◆ iterator

template<class T, class H = std::hash< T >>
using ADS::HashMultiset< T, H >::iterator = const_iterator

the same, constant

◆ value_type

template<class T, class H = std::hash< T >>
using ADS::HashMultiset< T, H >::value_type = std::pair< T , std::size_t >

a pair of an item and its occurrences

Constructor and destructor documentation

◆ HashMultiset()

template<class T, class H = std::hash< T >>
ADS::HashMultiset< T, H >::HashMultiset ( void )

the empty multiset

Member function documentation

◆ begin()

template<class T, class H = std::hash< T >>
const_iterator ADS::HashMultiset< T, H >::begin ( void ) const
inlinenodiscard

the iterator on the first pair

◆ cbegin()

template<class T, class H = std::hash< T >>
const_iterator ADS::HashMultiset< T, H >::cbegin ( void ) const
inlinenodiscard

as begin()

◆ cend()

template<class T, class H = std::hash< T >>
const_iterator ADS::HashMultiset< T, H >::cend ( void ) const
inlinenodiscard

as end()

◆ contains()

template<class T, class H = std::hash< T >>
bool ADS::HashMultiset< T, H >::contains ( const T & x) const
nodiscard

whether \( x \) occurs at least once

◆ count()

template<class T, class H = std::hash< T >>
std::size_t ADS::HashMultiset< T, H >::count ( const T & x) const
nodiscard

the occurrences of \( x \), 0 if none

◆ distinct()

template<class T, class H = std::hash< T >>
std::size_t ADS::HashMultiset< T, H >::distinct ( void ) const
nodiscard

the number of distinct items

◆ empty()

template<class T, class H = std::hash< T >>
bool ADS::HashMultiset< T, H >::empty ( void ) const
nodiscard

whether the multiset has no item

◆ end()

template<class T, class H = std::hash< T >>
const_iterator ADS::HashMultiset< T, H >::end ( void ) const
inlinenodiscard

the iterator past the last pair

◆ forEach()

template<class T, class H = std::hash< T >>
template<class F>
void ADS::HashMultiset< T, H >::forEach ( F && f) const

f( x , c ) on the distinct items and their occurrences

◆ insert()

template<class T, class H = std::hash< T >>
void ADS::HashMultiset< T, H >::insert ( const T & x)

one occurrence of \( x \) more

In pseudocode (exercise 8.10), \( D \) the table of the counters:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{insert}( x )\quad \triangleright\ D \text{ maps an item to its copies} \cr 2 & \quad D.\mathrm{insert}( x , 1 + \text{the copies of } x \text{, } 0 \text{ if } D.\mathrm{lookup}( x ) = \textbf{nil} ) \end{array}} \]

Postcondition
one occurrence of \( x \) more

◆ remove()

template<class T, class H = std::hash< T >>
void ADS::HashMultiset< T, H >::remove ( const T & x)

one occurrence of \( x \) less, if there is one

In pseudocode (exercise 8.10):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{remove}( x )\quad \triangleright \ \text{one copy} \cr 2 & \quad c \gets D.\mathrm{lookup}( x );\ \textbf{if}\ c = \textbf{nil}\ \textbf{then return} \cr 3 & \quad \textbf{if}\ c > 1\ \textbf{then}\ D.\mathrm{insert}( x , c - 1 )\ \textbf{else}\ D.\mathrm{remove}( x ) \end{array}} \]

Postcondition
one occurrence of \( x \) less, or none

◆ size()

template<class T, class H = std::hash< T >>
std::size_t ADS::HashMultiset< T, H >::size ( void ) const
nodiscard

the number of items, each counted as many times as it occurs


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