ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
RealTimeMinDeque.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------ File RealTimeMinDeque.h -------------------------*/
3/*--------------------------------------------------------------------------*/
57/*--------------------------------------------------------------------------*/
58/*----------------------------- DEFINITIONS --------------------------------*/
59/*--------------------------------------------------------------------------*/
60
61#ifndef __ADS_RealTimeMinDeque
62 #define __ADS_RealTimeMinDeque
63/* self-identification: #endif constant */
64
65/*--------------------------------------------------------------------------*/
66/*------------------------------ INCLUDES ----------------------------------*/
67/*--------------------------------------------------------------------------*/
68
69#include "ADS/Contract.h"
70#include "ADS/Portable.h"
72
73#include <algorithm>
74#include <array>
75#include <concepts>
76#include <cstddef>
77#include <functional>
78#include <initializer_list>
79#include <utility>
80
81/*--------------------------------------------------------------------------*/
82/*--------------------------- NAMESPACE ------------------------------------*/
83/*--------------------------------------------------------------------------*/
84
85namespace ADS
86{
87
88/*--------------------------------------------------------------------------*/
89/*------------------------- CLASS RealTimeMinDeque -------------------------*/
90/*--------------------------------------------------------------------------*/
91
94template< std::copy_constructible T , class C = std::less<> >
96{
97
98/*--------------------------------------------------------------------------*/
99 public:
100 using Item = T;
101
103 explicit RealTimeMinDeque( C less = C() )
104 : f_A{ Array( 16 ) , Array( 16 ) } , f_cells( std::move( less ) ) { }
105
108
111 : f_A{ Array( 16 ) , Array( 16 ) } , f_cells( o.f_cells ) {
112 swap( o );
113 }
114
117
120 swap( o );
121 return( *this );
122 }
123
125 void swap( RealTimeMinDeque & o ) noexcept;
126
128 [[nodiscard]] bool empty( void ) const { return( f_n == 0 ); }
129
131 [[nodiscard]] std::size_t size( void ) const { return( f_n ); }
132
135 void push_front( const T & x ) { push( 0 , x ); }
136
139 void push_back( const T & x ) { push( 1 , x ); }
140
144 T pop_front( void ) { return( pop( 0 ) ); }
145
149 T pop_back( void ) { return( pop( 1 ) ); }
150
153 [[nodiscard]] const T & front( void ) const { return( end( 0 ) ); }
154
157 [[nodiscard]] const T & back( void ) const { return( end( 1 ) ); }
158
161 [[nodiscard]] const T & min( void ) const;
162
164 template< class F >
165 void forEach( F && f ) const;
166
168 void clear( void );
169
170/*--------------------------------------------------------------------------*/
171 private:
172 using Array = detail::CellArray< T , std::size_t >;
173 using Cells = detail::MinCells< T , C >;
174
177 static constexpr int kSteps = 12;
178 static constexpr std::size_t kSmall = 32;
179
181 void push( int s , const T & x );
182
208 T pop( int s );
209
211 const T & end( int s ) const;
212
226 [[nodiscard]] bool due( void ) const;
227
230 void afterOp( void );
231
256 void start( void );
257
259 void steps( int k );
260
261 std::array< Array , 2 > f_A;
262 std::array< Array , 2 > f_new;
263 std::array< Array , 4 > f_old;
264 int f_g = 0;
265 std::size_t f_p = 0;
266 std::size_t f_cs = 0;
267 std::size_t f_cg = 0;
268 std::size_t f_t = 0;
269 std::size_t f_n = 0;
270 bool f_rb = false;
271 ADS_NO_UNIQUE_ADDRESS Cells f_cells;
272
273 }; // end( class RealTimeMinDeque )
274
275/*--------------------------------------------------------------------------*/
276
277} // end( namespace ADS )
278
279/*--------------------------------------------------------------------------*/
280/*-------------------------- IMPLEMENTATION --------------------------------*/
281/*--------------------------------------------------------------------------*/
282
283#include "ADS/queue/impl/RealTimeMinDeque.tpp"
284
285/*--------------------------------------------------------------------------*/
286
287#endif /* RealTimeMinDeque.h included */
288
289/*--------------------------------------------------------------------------*/
290/*---------------------- End File RealTimeMinDeque.h -----------------------*/
291/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
The QUEUE with the minimum of exercise 3.15 of Morin's book in worst-case time per operation,...
bool empty(void) const
true if there is no item
Definition RealTimeMinDeque.h:128
RealTimeMinDeque & operator=(const RealTimeMinDeque &o)
the items of o, by copy and swap
RealTimeMinDeque(C less=C())
the empty deque, ordered by less
Definition RealTimeMinDeque.h:103
T pop_front(void)
removes the item at the front and returns it
Definition RealTimeMinDeque.h:144
T Item
the type of the items
Definition RealTimeMinDeque.h:100
void forEach(F &&f) const
f( x ) on the items from the front to the back,
const T & min(void) const
the least item, the lesser of the minima of the two stacks
void clear(void)
removes all the items
void push_back(const T &x)
at the back, on
Definition RealTimeMinDeque.h:139
RealTimeMinDeque(const RealTimeMinDeque &o)
a copy, item by item, in time
const T & back(void) const
the item at the back
Definition RealTimeMinDeque.h:157
RealTimeMinDeque(RealTimeMinDeque &&o) noexcept
the items of o, which is left empty
Definition RealTimeMinDeque.h:110
void swap(RealTimeMinDeque &o) noexcept
exchanges the items with o
RealTimeMinDeque & operator=(RealTimeMinDeque &&o) noexcept
the items of o, exchanged with those of this deque
Definition RealTimeMinDeque.h:119
const T & front(void) const
the item at the front
Definition RealTimeMinDeque.h:153
std::size_t size(void) const
the number of items
Definition RealTimeMinDeque.h:131
T pop_back(void)
removes the item at the back and returns it
Definition RealTimeMinDeque.h:149
void push_front(const T &x)
at the front, on
Definition RealTimeMinDeque.h:135
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition Portable.h:81
Definition ADT.h:96