ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
SortedListSet.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*-------------------------- File SortedListSet.h --------------------------*/
3/*--------------------------------------------------------------------------*/
31/*--------------------------------------------------------------------------*/
32/*----------------------------- DEFINITIONS --------------------------------*/
33/*--------------------------------------------------------------------------*/
34
35#ifndef __ADS_SortedListSet
36 #define __ADS_SortedListSet
37/* self-identification: #endif constant */
38
39/*--------------------------------------------------------------------------*/
40/*------------------------------ INCLUDES ----------------------------------*/
41/*--------------------------------------------------------------------------*/
42
43#include "ADS/Contract.h"
44#include "ADS/sequence/List.h"
46
47#include <algorithm>
48#include <concepts>
49#include <cstddef>
50#include <functional>
51#include <optional>
52#include <stdexcept>
53#include <utility>
54#include <vector>
55
56/*--------------------------------------------------------------------------*/
57/*--------------------------- NAMESPACE ------------------------------------*/
58/*--------------------------------------------------------------------------*/
59
60namespace ADS
61{
62
63/*--------------------------------------------------------------------------*/
64/*-------------------------- CLASS SortedListSet ---------------------------*/
65/*--------------------------------------------------------------------------*/
66
68template< std::totally_ordered T >
70{
71
72/*--------------------------------------------------------------------------*/
73 public:
74 using Item = T;
75
77 SortedListSet( void ) = default;
78
80 SortedListSet( std::initializer_list< T > items );
81
83 [[nodiscard]] std::size_t size( void ) const;
84
86 [[nodiscard]] bool empty( void ) const;
87
90 [[nodiscard]] bool contains( const T & x ) const;
91
106 void insert( const T & x );
107
111 void insertLast( const T & x );
112
127 void remove( const T & x );
128
131 [[nodiscard]] std::optional< T > min( void ) const;
132
135 [[nodiscard]] std::optional< T > max( void ) const;
136
138 template< class F >
139 void forEach( F && f ) const;
140
142 [[nodiscard]] const List< T > & list( void ) const;
143
144/*------------------------- THE STANDARD INTERFACE -------------------------*/
145
146 // a constant view of the items in increasing order, bidirectional
147
148 using value_type = T;
149 using size_type = std::size_t;
150 using difference_type = std::ptrdiff_t;
151 using reference = const T &;
152 using const_reference = const T &;
156
158 [[nodiscard]] const_iterator begin( void ) const { return( f_L.begin() ); }
160 [[nodiscard]] const_iterator end( void ) const { return( f_L.end() ); }
162 [[nodiscard]] const_iterator cbegin( void ) const { return( begin() ); }
164 [[nodiscard]] const_iterator cend( void ) const { return( end() ); }
165
166/*--------------------------------------------------------------------------*/
167 private:
169 typename List< T >::Pos lower( const T & x ) const;
170
172 [[nodiscard]] bool sorted( void ) const;
173
174 List< T > f_L;
175 std::size_t f_size = 0;
176
177 }; // end( class SortedListSet )
178
214template< class T >
216 const SortedListSet< T > & B , bool a , bool b ,
217 bool both );
218
229template< class T >
231 const SortedListSet< T > & B );
232
243template< class T >
245 const SortedListSet< T > & B );
246
257template< class T >
259 const SortedListSet< T > & B );
260
271template< class T >
273 const SortedListSet< T > & B );
274
275} // end( namespace ADS )
276
277/*--------------------------------------------------------------------------*/
278/*-------------------------- IMPLEMENTATION --------------------------------*/
279/*--------------------------------------------------------------------------*/
280
281#include "ADS/set/impl/SortedListSet.tpp"
282
283/*--------------------------------------------------------------------------*/
284
285#endif /* SortedListSet.h included */
286
287/*--------------------------------------------------------------------------*/
288/*------------------------ End File SortedListSet.h ------------------------*/
289/*--------------------------------------------------------------------------*/
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 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
a set as a list sorted in increasing order
Definition SortedListSet.h:70
bool empty(void) const
whether the set has no item
bool contains(const T &x) const
whether is in the set, by a scan that stops at the first item not smaller than , time
T value_type
the items
Definition SortedListSet.h:148
void insertLast(const T &x)
, larger than all the items, at the end of the list, time
SortedListSet(void)=default
the empty set
const_iterator end(void) const
the iterator past the largest item
Definition SortedListSet.h:160
const_iterator begin(void) const
the iterator on the smallest item
Definition SortedListSet.h:158
const T & reference
a constant reference
Definition SortedListSet.h:151
void remove(const T &x)
out of the set, time
SortedListSet(std::initializer_list< T > items)
the set of the given items, in any order, a repeated one taken once
std::optional< T > min(void) const
the smallest item, at the head, none if the set is empty, time
T Item
the type of the items
Definition SortedListSet.h:74
std::size_t size(void) const
the number of items
typename List< T >::const_iterator const_iterator
the iterator of the list, constant
Definition SortedListSet.h:154
std::size_t size_type
the sizes
Definition SortedListSet.h:149
std::ptrdiff_t difference_type
the distances
Definition SortedListSet.h:150
const_iterator iterator
the same, constant
Definition SortedListSet.h:155
const_iterator cend(void) const
as end()
Definition SortedListSet.h:164
const_iterator cbegin(void) const
as begin()
Definition SortedListSet.h:162
const T & const_reference
a constant reference
Definition SortedListSet.h:152
std::optional< T > max(void) const
the largest item, at the tail, none if the set is empty, time
void forEach(F &&f) const
f( x ) on the items in increasing order, time
void insert(const T &x)
into the set, time, to keep the order
const List< T > & list(void) const
the sorted list of the items
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
SortedListSet< T > merge(const SortedListSet< T > &A, const SortedListSet< T > &B, bool a, bool b, bool both)
the merge of the sorted lists of and : an item of only, of only or of both goes into the result if...
Definition ADT.h:96