ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
UniqueQueue.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*--------------------------- File UniqueQueue.h ---------------------------*/
3/*--------------------------------------------------------------------------*/
26/*--------------------------------------------------------------------------*/
27/*----------------------------- DEFINITIONS --------------------------------*/
28/*--------------------------------------------------------------------------*/
29
30#ifndef __ADS_UniqueQueue
31 #define __ADS_UniqueQueue
32/* self-identification: #endif constant */
33
34/*--------------------------------------------------------------------------*/
35/*------------------------------ INCLUDES ----------------------------------*/
36/*--------------------------------------------------------------------------*/
37
38#include "ADS/Contract.h"
39#include "ADS/sequence/List.h"
40
41#include <concepts>
42#include <cstddef>
43
44/*--------------------------------------------------------------------------*/
45/*--------------------------- NAMESPACE ------------------------------------*/
46/*--------------------------------------------------------------------------*/
47
48namespace ADS
49{
50
51/*--------------------------------------------------------------------------*/
52/*-------------------------- CLASS UniqueQueue -----------------------------*/
53/*--------------------------------------------------------------------------*/
54
60
64template< std::equality_comparable T , Duplicate D = Duplicate::IGNORE_NEW >
66{
67
68/*--------------------------------------------------------------------------*/
69 public:
70 using Item = T;
71
73 [[nodiscard]] bool empty( void ) const;
74
91 void enqueue( const T & v );
92
95 T dequeue( void );
96
99 [[nodiscard]] const T & top( void ) const;
100
102 [[nodiscard]] bool contains( const T & v ) const;
103
105 [[nodiscard]] std::size_t size( void ) const;
106
107/*------------------------- THE STANDARD INTERFACE -------------------------*/
108
109 // a constant view of the items from the front to the back, bidirectional;
110 // a change through it could break the uniqueness
111
112 using value_type = T;
113 using size_type = std::size_t;
114 using difference_type = std::ptrdiff_t;
115 using reference = const T &;
116 using const_reference = const T &;
121
123 [[nodiscard]] const_iterator begin( void ) const { return( f_L.begin() ); }
124
126 [[nodiscard]] const_iterator end( void ) const { return( f_L.end() ); }
127
129 [[nodiscard]] const_iterator cbegin( void ) const { return( begin() ); }
130
132 [[nodiscard]] const_iterator cend( void ) const { return( end() ); }
133
134/*--------------------------------------------------------------------------*/
135 private:
137 [[nodiscard]] bool unique( void ) const;
138
140 [[nodiscard]] typename List< T >::Pos find( const T & v ) const;
141
142 List< T > f_L;
143 std::size_t f_size = 0;
144
145 }; // end( class UniqueQueue )
146
147/*--------------------------------------------------------------------------*/
148
149} // end( namespace ADS )
150
151/*--------------------------------------------------------------------------*/
152/*-------------------------- IMPLEMENTATION --------------------------------*/
153/*--------------------------------------------------------------------------*/
154
155#include "ADS/queue/impl/UniqueQueue.tpp"
156
157/*--------------------------------------------------------------------------*/
158
159#endif /* UniqueQueue.h included */
160
161/*--------------------------------------------------------------------------*/
162/*------------------------- End File UniqueQueue.h -------------------------*/
163/*--------------------------------------------------------------------------*/
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 ...
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 QUEUE with no duplicates; the equality of T must be an equivalence, so an item unequal to itself (e...
Definition UniqueQueue.h:66
typename List< T >::const_iterator iterator
a constant iterator of the list
Definition UniqueQueue.h:118
T value_type
the type of the items
Definition UniqueQueue.h:112
bool empty(void) const
true if there is no item
const_iterator end(void) const
the iterator past the item at the back
Definition UniqueQueue.h:126
const_iterator cend(void) const
as end()
Definition UniqueQueue.h:132
void enqueue(const T &v)
puts at the back, unless the policy keeps an old copy of it
T dequeue(void)
removes the item at the front and returns it
T Item
the type of the items
Definition UniqueQueue.h:70
const T & top(void) const
the item at the front
const_iterator begin(void) const
the iterator on the item at the front
Definition UniqueQueue.h:123
const T & reference
a constant reference
Definition UniqueQueue.h:115
std::size_t size_type
the type of the sizes
Definition UniqueQueue.h:113
std::ptrdiff_t difference_type
the type of the distances
Definition UniqueQueue.h:114
typename List< T >::const_iterator const_iterator
a constant iterator of the list
Definition UniqueQueue.h:120
std::size_t size(void) const
the number of items,
const_iterator cbegin(void) const
as begin()
Definition UniqueQueue.h:129
const T & const_reference
a constant reference
Definition UniqueQueue.h:116
bool contains(const T &v) const
whether is in the queue,
Duplicate
what enqueue() does with an item already in the queue
Definition UniqueQueue.h:56
@ FORGET_OLD
the old copy is removed, the item goes to the back
Definition UniqueQueue.h:58
@ IGNORE_NEW
the queue is left as it is
Definition UniqueQueue.h:57
Definition ADT.h:96