ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
HashMultiset.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File HashMultiset.h ---------------------------*/
3/*--------------------------------------------------------------------------*/
24/*--------------------------------------------------------------------------*/
25/*----------------------------- DEFINITIONS --------------------------------*/
26/*--------------------------------------------------------------------------*/
27
28#ifndef __ADS_HashMultiset
29 #define __ADS_HashMultiset
30/* self-identification: #endif constant */
31
32/*--------------------------------------------------------------------------*/
33/*------------------------------ INCLUDES ----------------------------------*/
34/*--------------------------------------------------------------------------*/
35
36#include "ADS/Contract.h"
38
39#include <algorithm>
40#include <concepts>
41#include <cstddef>
42#include <functional>
43#include <optional>
44#include <stdexcept>
45#include <utility>
46#include <vector>
47
48/*--------------------------------------------------------------------------*/
49/*--------------------------- NAMESPACE ------------------------------------*/
50/*--------------------------------------------------------------------------*/
51
52namespace ADS
53{
54
55/*--------------------------------------------------------------------------*/
56/*--------------------------- CLASS HashMultiset ---------------------------*/
57/*--------------------------------------------------------------------------*/
58
62template< class T , class H = std::hash< T > >
64{
65
66/*--------------------------------------------------------------------------*/
67 public:
68 using Item = T;
69
71 HashMultiset( void );
72
74 [[nodiscard]] std::size_t size( void ) const;
75
77 [[nodiscard]] std::size_t distinct( void ) const;
78
80 [[nodiscard]] bool empty( void ) const;
81
83 [[nodiscard]] bool contains( const T & x ) const;
84
86 [[nodiscard]] std::size_t count( const T & x ) const;
87
100 void insert( const T & x );
101
116 void remove( const T & x );
117
119 template< class F >
120 void forEach( F && f ) const;
121
122/*------------------------- THE STANDARD INTERFACE -------------------------*/
123
124 // a constant view of the pairs ( item , count ) of the distinct items,
125 // forward
126
128 using value_type = std::pair< T , std::size_t >;
131 typename ChainedHashTable< T , std::size_t , Chain::FRONT ,
134
136 [[nodiscard]] const_iterator begin( void ) const {
137 return( f_count.begin() );
138 }
139
140 [[nodiscard]] const_iterator end( void ) const { return( f_count.end() ); }
142 [[nodiscard]] const_iterator cbegin( void ) const { return( begin() ); }
144 [[nodiscard]] const_iterator cend( void ) const { return( end() ); }
145
146/*--------------------------------------------------------------------------*/
147 private:
149 [[nodiscard]] bool counted( void ) const;
150
153 std::size_t f_size = 0;
154
155 }; // end( class HashMultiset )
156
157/*--------------------------------------------------------------------------*/
158
159} // end( namespace ADS )
160
161/*--------------------------------------------------------------------------*/
162/*-------------------------- IMPLEMENTATION --------------------------------*/
163/*--------------------------------------------------------------------------*/
164
165#include "ADS/set/impl/HashMultiset.tpp"
166
167/*--------------------------------------------------------------------------*/
168
169#endif /* HashMultiset.h included */
170
171/*--------------------------------------------------------------------------*/
172/*------------------------ End File HashMultiset.h -------------------------*/
173/*--------------------------------------------------------------------------*/
The hash table with lists of overflow of section 7.2.1, a realization of the DICTIONARY [see ADT....
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
a hash table with lists of overflow
Definition ChainedHashTable.h:103
std::size_t size(void) const
the number of items, each counted as many times as it occurs
const_iterator iterator
the same, constant
Definition HashMultiset.h:133
T Item
the type of the items
Definition HashMultiset.h:68
const_iterator begin(void) const
the iterator on the first pair
Definition HashMultiset.h:136
const_iterator end(void) const
the iterator past the last pair
Definition HashMultiset.h:140
bool empty(void) const
whether the multiset has no item
void remove(const T &x)
one occurrence of less, if there is one
std::size_t distinct(void) const
the number of distinct items
const_iterator cbegin(void) const
as begin()
Definition HashMultiset.h:142
typename ChainedHashTable< T, std::size_t, Chain::FRONT, H >::const_iterator const_iterator
the iterator of the table of the counters, constant
Definition HashMultiset.h:130
std::size_t count(const T &x) const
the occurrences of , 0 if none
const_iterator cend(void) const
as end()
Definition HashMultiset.h:144
bool contains(const T &x) const
whether occurs at least once
void forEach(F &&f) const
f( x , c ) on the distinct items and their occurrences
HashMultiset(void)
the empty multiset
std::pair< T, std::size_t > value_type
a pair of an item and its occurrences
Definition HashMultiset.h:128
void insert(const T &x)
one occurrence of more
@ FRONT
a new key at the head, nothing moves
Definition ChainedHashTable.h:93
Definition ADT.h:96