ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
DictionarySet.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File DictionarySet.h --------------------------*/
3/*--------------------------------------------------------------------------*/
42/*--------------------------------------------------------------------------*/
43/*----------------------------- DEFINITIONS --------------------------------*/
44/*--------------------------------------------------------------------------*/
45
46#ifndef __ADS_DictionarySet
47 #define __ADS_DictionarySet
48/* self-identification: #endif constant */
49
50/*--------------------------------------------------------------------------*/
51/*------------------------------ INCLUDES ----------------------------------*/
52/*--------------------------------------------------------------------------*/
53
54#include "ADS/Contract.h"
55#include "ADS/Iterators.h"
60#include "ADS/tree/SearchTree.h"
61
62#include <algorithm>
63#include <concepts>
64#include <cstddef>
65#include <functional>
66#include <optional>
67#include <ranges>
68#include <stdexcept>
69#include <utility>
70#include <vector>
71
72/*--------------------------------------------------------------------------*/
73/*--------------------------- NAMESPACE ------------------------------------*/
74/*--------------------------------------------------------------------------*/
75
76namespace ADS
77{
78
79/*--------------------------------------------------------------------------*/
80/*-------------------------- CLASS DictionarySet ---------------------------*/
81/*--------------------------------------------------------------------------*/
82
85template< class D >
87{
88
89/*--------------------------------------------------------------------------*/
90 public:
91 using Item = typename D::Key;
92
94 template< class... A >
95 requires std::constructible_from< D , A... >
96 explicit DictionarySet( A &&... a );
97
99 [[nodiscard]] std::size_t size( void ) const;
100
102 [[nodiscard]] bool empty( void ) const;
103
105 [[nodiscard]] bool contains( const Item & x ) const;
106
126 bool insert( const Item & x );
127
144 bool remove( const Item & x );
145
148 [[nodiscard]] const Item * find( const Item & x ) const
149 requires KeyedDictionary< D >;
150
154 [[nodiscard]] const Item * lowerBound( const Item & x ) const
155 requires OrderedDictionary< D >;
156
158 template< class F >
159 void forEach( F && f ) const;
160
162 [[nodiscard]] const D & dictionary( void ) const;
163
164/*------------------------- THE STANDARD INTERFACE -------------------------*/
165
166 // a constant view of the items, the keys of the dictionary in its order,
167 // when the dictionary has iterators
168
170 [[nodiscard]] auto begin( void ) const
171 requires std::ranges::forward_range< const D >
172 {
173 return( KeyIterator( std::ranges::begin( std::as_const( f_d ) ) ) );
174 }
175
177 [[nodiscard]] auto end( void ) const
178 requires std::ranges::forward_range< const D >
179 {
180 return( KeyIterator( std::ranges::end( std::as_const( f_d ) ) ) );
181 }
182
183/*--------------------------------------------------------------------------*/
184 private:
186 [[nodiscard]] static typename D::Value mark( void );
187
188 mutable D f_d;
189
190 }; // end( class DictionarySet )
191
193template< class T , class H = std::hash< T > >
196
198template< class T , class H = std::hash< T > >
200
202template< std::totally_ordered T >
204
205} // end( namespace ADS )
206
207/*--------------------------------------------------------------------------*/
208/*-------------------------- IMPLEMENTATION --------------------------------*/
209/*--------------------------------------------------------------------------*/
210
211#include "ADS/set/impl/DictionarySet.tpp"
212
213/*--------------------------------------------------------------------------*/
214
215#endif /* DictionarySet.h included */
216
217/*--------------------------------------------------------------------------*/
218/*------------------------ End File DictionarySet.h ------------------------*/
219/*--------------------------------------------------------------------------*/
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,...
The iterators that the containers of the library have in common, beyond the book: they give a contain...
The hash table with open addressing of section 7.2.2, a realization of the DICTIONARY [see ADT....
The binary search tree (ABR) and the Red-Black tree of the book, as a DICTIONARY [see ADT....
The interfaces of chapter 1 of Morin's book for the sets, beyond the book, as concepts of C++20 [see ...
The operations of chapter 8 on any SET that can be copied and has the foreach, forEach( f ): the unio...
a set on a DICTIONARY D, an item being a key: a USet of Morin if D is a KeyedDictionary,...
Definition DictionarySet.h:87
const Item * find(const Item &x) const
the address of the item equal to , nil if none, by findKey() of the dictionary: the find( x ) of a US...
bool contains(const Item &x) const
whether is a key of the dictionary
auto begin(void) const
the iterator on the first key of the dictionary
Definition DictionarySet.h:170
const D & dictionary(void) const
the dictionary
bool remove(const Item &x)
out of the set, the key removed from the dictionary
DictionarySet(A &&... a)
the empty set on the dictionary D( a... )
std::size_t size(void) const
the number of items, the keys of the dictionary
void forEach(F &&f) const
f( x ) on the items, in the order of the dictionary
bool empty(void) const
whether the set has no item
const Item * lowerBound(const Item &x) const
the address of the smallest item not smaller than , nil if none, by lowerBoundKey() of the dictionary...
typename D::Key Item
the type of the items
Definition DictionarySet.h:91
auto end(void) const
the iterator past the last key of the dictionary
Definition DictionarySet.h:177
bool insert(const Item &x)
into the set, as the key of the value true (or of the value made by default, for values that are not ...
the member first of what the iterator I reads, with the category of I up to bidirectional
Definition Iterators.h:793
a dictionary that gives the address of the key equal to the one asked, on which DictionarySet is a US...
Definition SetInterfaces.h:110
a KeyedDictionary that gives the address of the smallest key not smaller than the one asked,...
Definition SetInterfaces.h:123
DictionarySet< RedBlackTree< T, bool > > TreeSet
the set on a Red-Black tree
Definition DictionarySet.h:203
DictionarySet< OpenHashTable< T, bool, H > > OpenHashSet
the set on a hash table with open addressing
Definition DictionarySet.h:199
DictionarySet< ChainedHashTable< T, bool, Chain::FRONT, H > > ChainedHashSet
the set on a hash table with lists of overflow
Definition DictionarySet.h:194
Definition ADT.h:96