ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
RealTimeMinQueue.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------ File RealTimeMinQueue.h -------------------------*/
3/*--------------------------------------------------------------------------*/
49/*--------------------------------------------------------------------------*/
50/*----------------------------- DEFINITIONS --------------------------------*/
51/*--------------------------------------------------------------------------*/
52
53#ifndef __ADS_RealTimeMinQueue
54 #define __ADS_RealTimeMinQueue
55/* self-identification: #endif constant */
56
57/*--------------------------------------------------------------------------*/
58/*------------------------------ INCLUDES ----------------------------------*/
59/*--------------------------------------------------------------------------*/
60
61#include "ADS/Contract.h"
62#include "ADS/Portable.h"
64
65#include <algorithm>
66#include <cstddef>
67#include <functional>
68#include <memory>
69#include <utility>
70
71/*--------------------------------------------------------------------------*/
72/*--------------------------- NAMESPACE ------------------------------------*/
73/*--------------------------------------------------------------------------*/
74
75namespace ADS
76{
77
78namespace detail
79{
80
85template< class T , class C >
86struct MinCells
87{
88 using Item = T;
89 using Summary = std::size_t;
90
92 explicit MinCells( C l = C() ) : less( std::move( l ) ) { }
93
110 template< class A , class U >
111 void push( A & a , U && x ) const {
112 const std::size_t h = a.hi();
113 const std::size_t m =
114 ( h > a.lo() ) && ! less( x , a.at( a.summary( h - 1 ) ) )
115 ? a.summary( h - 1 )
116 : h;
117 a.push( std::forward< U >( x ) , m );
118 }
119
121 template< class A , class U >
122 void pushFront( A & a , U && x ) const {
123 push( a , std::forward< U >( x ) );
124 }
125
127 template< class A , class U >
128 void pushBack( A & a , U && x ) const {
129 push( a , std::forward< U >( x ) );
130 }
131
133 template< class A >
134 [[nodiscard]] const T & min( const A & a ) const {
135 return( a.at( a.summary( a.hi() - 1 ) ) );
136 }
137
138 ADS_NO_UNIQUE_ADDRESS C less;
139 };
140
141} // end( namespace detail )
142
143/*--------------------------------------------------------------------------*/
144/*------------------------- CLASS RealTimeMinQueue -------------------------*/
145/*--------------------------------------------------------------------------*/
146
149template< class T , class C = std::less<> >
151{
152
153/*--------------------------------------------------------------------------*/
154 public:
155 using Item = T;
156
158 explicit RealTimeMinQueue( C less = C() )
159 : f_q( Cells( std::move( less ) ) ) { }
160
162 RealTimeMinQueue( const RealTimeMinQueue & o ) = default;
163
165 RealTimeMinQueue( RealTimeMinQueue && o ) noexcept = default;
166
169
171 RealTimeMinQueue & operator=( RealTimeMinQueue && o ) noexcept = default;
172
174 void swap( RealTimeMinQueue & o ) noexcept { f_q.swap( o.f_q ); }
175
177 [[nodiscard]] bool empty( void ) const { return( f_q.size() == 0 ); }
178
180 [[nodiscard]] std::size_t size( void ) const { return( f_q.size() ); }
181
185 void enqueue( const T & x );
186
216 T dequeue( void );
217
220 [[nodiscard]] const T & top( void ) const;
221
242 [[nodiscard]] const T & min( void ) const;
243
245 template< class F >
246 void forEach( F && f ) const;
247
249 void clear( void );
250
251/*--------------------------------------------------------------------------*/
252 private:
253 using Cells = detail::MinCells< T , C >;
254
257 detail::RealTimeRotation< Cells > f_q;
258
259 }; // end( class RealTimeMinQueue )
260
261/*--------------------------------------------------------------------------*/
262
263} // end( namespace ADS )
264
265/*--------------------------------------------------------------------------*/
266/*-------------------------- IMPLEMENTATION --------------------------------*/
267/*--------------------------------------------------------------------------*/
268
269#include "ADS/queue/impl/RealTimeMinQueue.tpp"
270
271/*--------------------------------------------------------------------------*/
272
273#endif /* RealTimeMinQueue.h included */
274
275/*--------------------------------------------------------------------------*/
276/*---------------------- End File RealTimeMinQueue.h -----------------------*/
277/*--------------------------------------------------------------------------*/
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 aggregate of a sliding window, beyond the book: a QUEUE of values of the monoid G [see Algebra....
T dequeue(void)
removes the item at the front, the top of , and returns it, with three moves of a rotation if one is ...
RealTimeMinQueue & operator=(const RealTimeMinQueue &o)=default
the items of o, by copy and swap
void clear(void)
removes all the items
void enqueue(const T &x)
at the back, on the stack , and three moves of a rotation if one is going on
const T & min(void) const
the least item, the least of the minima of the parts
RealTimeMinQueue & operator=(RealTimeMinQueue &&o) noexcept=default
the items of o, exchanged with those of this queue
T Item
the type of the items
Definition RealTimeMinQueue.h:155
RealTimeMinQueue(C less=C())
the empty queue, ordered by less
Definition RealTimeMinQueue.h:158
bool empty(void) const
true if there is no item
Definition RealTimeMinQueue.h:177
const T & top(void) const
the item at the front, the top of
void swap(RealTimeMinQueue &o) noexcept
exchanges the items with o
Definition RealTimeMinQueue.h:174
RealTimeMinQueue(RealTimeMinQueue &&o) noexcept=default
the items of o, which is left empty
void forEach(F &&f) const
f( x ) on the items from the front to the back,
std::size_t size(void) const
the number of items
Definition RealTimeMinQueue.h:180
RealTimeMinQueue(const RealTimeMinQueue &o)=default
a copy, item by item, in time
#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