ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ListSet.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*----------------------------- File ListSet.h -----------------------------*/
3/*--------------------------------------------------------------------------*/
26/*--------------------------------------------------------------------------*/
27/*----------------------------- DEFINITIONS --------------------------------*/
28/*--------------------------------------------------------------------------*/
29
30#ifndef __ADS_ListSet
31 #define __ADS_ListSet
32/* self-identification: #endif constant */
33
34/*--------------------------------------------------------------------------*/
35/*------------------------------ INCLUDES ----------------------------------*/
36/*--------------------------------------------------------------------------*/
37
38#include "ADS/Contract.h"
39#include "ADS/sequence/List.h"
41
42#include <algorithm>
43#include <concepts>
44#include <cstddef>
45#include <functional>
46#include <optional>
47#include <stdexcept>
48#include <utility>
49#include <vector>
50
51/*--------------------------------------------------------------------------*/
52/*--------------------------- NAMESPACE ------------------------------------*/
53/*--------------------------------------------------------------------------*/
54
55namespace ADS
56{
57
58/*--------------------------------------------------------------------------*/
59/*----------------------------- CLASS ListSet ------------------------------*/
60/*--------------------------------------------------------------------------*/
61
63template< std::equality_comparable T >
65{
66
67/*--------------------------------------------------------------------------*/
68 public:
69 using Item = T;
70
72 ListSet( void ) = default;
73
75 ListSet( std::initializer_list< T > items );
76
78 [[nodiscard]] std::size_t size( void ) const;
79
81 [[nodiscard]] bool empty( void ) const;
82
85 [[nodiscard]] bool contains( const T & x ) const;
86
99 void insert( const T & x );
100
104 void insertNew( const T & x );
105
119 void remove( const T & x );
120
123 [[nodiscard]] std::optional< T > min( void ) const
124 requires std::totally_ordered< T >;
125
127 template< class F >
128 void forEach( F && f ) const;
129
130/*------------------------- THE STANDARD INTERFACE -------------------------*/
131
132 // a constant view of the items in the order of the list, bidirectional
133
134 using value_type = T;
135 using size_type = std::size_t;
136 using difference_type = std::ptrdiff_t;
137 using reference = const T &;
138 using const_reference = const T &;
142
144 [[nodiscard]] const_iterator begin( void ) const { return( f_L.begin() ); }
146 [[nodiscard]] const_iterator end( void ) const { return( f_L.end() ); }
148 [[nodiscard]] const_iterator cbegin( void ) const { return( begin() ); }
150 [[nodiscard]] const_iterator cend( void ) const { return( end() ); }
151
152/*--------------------------------------------------------------------------*/
153 private:
154 typename List< T >::Pos find( const T & x ) const;
155
157 [[nodiscard]] bool distinct( void ) const;
158
159 List< T > f_L;
160 std::size_t f_size = 0;
161
162 }; // end( class ListSet )
163
181template< class T >
183
197template< class T >
199 const ListSet< T > & B );
200
214template< class T >
216
231template< class T >
233 const ListSet< T > & B );
234
235} // end( namespace ADS )
236
237/*--------------------------------------------------------------------------*/
238/*-------------------------- IMPLEMENTATION --------------------------------*/
239/*--------------------------------------------------------------------------*/
240
241#include "ADS/set/impl/ListSet.tpp"
242
243/*--------------------------------------------------------------------------*/
244
245#endif /* ListSet.h included */
246
247/*--------------------------------------------------------------------------*/
248/*--------------------------- End File ListSet.h ---------------------------*/
249/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The LIST of the book: a SEQUENCE [see ADT.h] realized as a bidirectional circular list of cells with ...
The operations of chapter 8 on any SET that can be copied and has the foreach, forEach( f ): the unio...
a set as an unsorted list
Definition ListSet.h:65
const T & reference
a constant reference
Definition ListSet.h:137
const_iterator iterator
the same, constant
Definition ListSet.h:141
const T & const_reference
a constant reference
Definition ListSet.h:138
const_iterator cend(void) const
as end()
Definition ListSet.h:150
std::size_t size_type
the sizes
Definition ListSet.h:135
const_iterator begin(void) const
the iterator on the item at the head of the list
Definition ListSet.h:144
bool contains(const T &x) const
whether is in the set, by a scan of the list, time
typename List< T >::const_iterator const_iterator
the iterator of the list, constant
Definition ListSet.h:140
bool empty(void) const
whether the set has no item
const_iterator cbegin(void) const
as begin()
Definition ListSet.h:148
const_iterator end(void) const
the iterator past the last item
Definition ListSet.h:146
std::size_t size(void) const
the number of items
std::ptrdiff_t difference_type
the distances
Definition ListSet.h:136
void insert(const T &x)
into the set, time, for the check that is not there
void forEach(F &&f) const
f( x ) on the items, from the last inserted, time
void remove(const T &x)
out of the set, time
std::optional< T > min(void) const
the smallest item, none if the set is empty, by a scan, time
T Item
the type of the items
Definition ListSet.h:69
void insertNew(const T &x)
, which must not be there, at the head of the list, time
ListSet(void)=default
the empty set
T value_type
the items
Definition ListSet.h:134
ListSet(std::initializer_list< T > items)
the set of the given items, a repeated one taken once
a SEQUENCE realized as a bidirectional circular list with a sentinel, its cells from a pool if Pooled
Definition List.h:118
Iterator< true > const_iterator
the iterator on the constant items
Definition List.h:324
Cell * Pos
a position is the address of a cell
Definition List.h:132
BoolSet setIntersection(const BoolSet &A, const BoolSet &B)
the intersection, a set of dimension
BoolSet setUnion(const BoolSet &A, const BoolSet &B)
the union, a set of dimension
BoolSet setDifference(const BoolSet &A, const BoolSet &B)
the difference, a set of dimension A.dim()
BoolSet setSymmetricDifference(const BoolSet &A, const BoolSet &B)
the symmetric difference, the items in exactly one of and , a set of dimension
Definition ADT.h:96