61#ifndef __ADS_RingDeque
62 #define __ADS_RingDeque
77#include <initializer_list>
89#define ADS_RING_INLINE ADS_ALWAYS_INLINE
91#define ADS_RING_NOINLINE ADS_NOINLINE
101template<
class T ,
bool Const >
104 using Item = std::conditional_t< Const , const T , T >;
108 using iterator_category = std::random_access_iterator_tag;
110 using value_type = T;
112 using difference_type = std::ptrdiff_t;
114 using reference = Item &;
116 using pointer = Item *;
119 MaskIterator(
void ) =
default;
120 MaskIterator( Item * A , std::size_t head , std::size_t mask , std::size_t i )
121 : f_A( A ) , f_head( head ) , f_mask( mask ) , f_i( i ) { }
125 requires( Const && ! K )
126 MaskIterator(
const MaskIterator< T , K > & o )
127 : f_A( o.f_A ) , f_head( o.f_head ) , f_mask( o.f_mask ) ,
131 reference operator*(
void )
const {
132 return( f_A[ ( f_head + f_i ) & f_mask ] );
135 pointer operator->(
void )
const {
return( &**
this ); }
137 reference operator[]( difference_type k )
const {
138 return( f_A[ ( f_head + f_i + std::size_t( k ) ) & f_mask ] );
142 MaskIterator & operator++(
void ) {
147 MaskIterator & operator--(
void ) {
152 MaskIterator operator++(
int ) {
158 MaskIterator operator--(
int ) {
164 MaskIterator & operator+=( difference_type k ) {
165 f_i += std::size_t( k );
169 MaskIterator & operator-=( difference_type k ) {
170 f_i -= std::size_t( k );
173 friend MaskIterator operator+( MaskIterator a , difference_type k ) {
176 friend MaskIterator operator+( difference_type k , MaskIterator a ) {
179 friend MaskIterator operator-( MaskIterator a , difference_type k ) {
182 friend difference_type operator-(
const MaskIterator & a ,
183 const MaskIterator & b ) {
184 return( difference_type( a.f_i - b.f_i ) );
186 bool operator==(
const MaskIterator & o )
const {
return( f_i == o.f_i ); }
187 std::strong_ordering operator<=>(
const MaskIterator & o )
const {
188 return( f_i <=> o.f_i );
192 template<
class ,
bool >
193 friend class MaskIterator;
195 Item * f_A =
nullptr;
196 std::size_t f_head = 0 , f_mask = 0;
224 using iterator = detail::MaskIterator< T , false >;
254 [[nodiscard]]
bool empty(
void )
const {
return( f_head == f_tail ); }
257 [[nodiscard]] std::size_t
size(
void )
const {
return( f_tail - f_head ); }
260 [[nodiscard]] std::size_t
capacity(
void )
const {
return( f_mask + 1 ); }
271 [[nodiscard]]
const T &
front(
void )
const;
275 [[nodiscard]] T &
back(
void );
279 [[nodiscard]]
const T &
back(
void )
const;
323 template<
class... Args >
341 template<
class... Args >
379 void insert( std::size_t i ,
const T & v );
436 return(
iterator( f_A , f_head , f_mask , 0 ) );
487 T & growBack( T && v );
488 T & growFront( T && v );
510 void shiftDown( std::size_t lo , std::size_t hi );
514 void shiftUp( std::size_t lo , std::size_t hi );
517 [[nodiscard]]
bool fits(
void )
const;
522 using Count = std::size_t;
525 Count f_mask = Count( -1 );
538#include "ADS/queue/impl/RingDeque.tpp"
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: ...
const_reverse_iterator rend(void) const
the constant iterator before the first item, backwards
Definition RingDeque.h:467
const_iterator cend(void) const
the constant iterator past the last item
Definition RingDeque.h:453
T & reference
a reference to an item
Definition RingDeque.h:220
std::ptrdiff_t difference_type
the type of the distances
Definition RingDeque.h:218
T & front(void)
the item at the front
const_iterator begin(void) const
the constant iterator on the first item
Definition RingDeque.h:443
const_reverse_iterator rbegin(void) const
the constant iterator on the last item, backwards
Definition RingDeque.h:463
void push_front(const T &v)
at the front, emplace_front( v )
Definition RingDeque.h:297
detail::MaskIterator< T, false > iterator
the iterator on the items
Definition RingDeque.h:224
T & emplace_back(Args &&... args)
the item built from args at the back, amortized
void pop_front(void)
removes the item at the front, advancing
const_iterator end(void) const
the constant iterator past the last item
Definition RingDeque.h:447
bool operator==(const RingDeque &o) const
the same items in the same order
void push_back(const T &v)
at the back, emplace_back( v )
Definition RingDeque.h:291
std::size_t size(void) const
the number of items, the difference of the two counters
Definition RingDeque.h:257
reverse_iterator rbegin(void)
the iterator on the last item, backwards
Definition RingDeque.h:455
const_iterator cbegin(void) const
the constant iterator on the first item
Definition RingDeque.h:451
void push_front(T &&v)
at the front, moved
Definition RingDeque.h:300
RingDeque(RingDeque &&o) noexcept
the vector of o, which is left empty with no capacity
reverse_iterator rend(void)
the iterator before the first item, backwards
Definition RingDeque.h:459
void reserve(std::size_t n)
at least places
void swap(RingDeque &o) noexcept
exchanges the vector with that of o
RingDeque(void)=default
the empty deque, with no places
iterator begin(void)
the iterator on the first item
Definition RingDeque.h:435
RingDeque & operator=(RingDeque o) noexcept
the items of o, by copy and swap
const T & front(void) const
the item at the front, constant
void insert(std::size_t i, const T &v)
puts at the rank , moving by one place the items on the shorter side of , in amortized time (the ad...
iterator end(void)
the iterator past the last item
Definition RingDeque.h:439
const T & const_reference
a constant reference to an item
Definition RingDeque.h:222
std::reverse_iterator< iterator > reverse_iterator
the iterator on the items, backwards
Definition RingDeque.h:228
T & back(void)
the item at the back
std::size_t capacity(void) const
the places, 0 or a power of 2
Definition RingDeque.h:260
T value_type
the type of the items
Definition RingDeque.h:214
const T & back(void) const
the item at the back, constant
T & emplace_front(Args &&... args)
the item built from args at the front, amortized
RingDeque(const RingDeque &o)
a copy of o
T & operator[](std::size_t i)
the item of rank from the front, at the place
std::reverse_iterator< const_iterator > const_reverse_iterator
the iterator on the constant items, backwards
Definition RingDeque.h:230
std::size_t size_type
the type of the sizes
Definition RingDeque.h:216
void clear(void)
removes all the items, the places kept
detail::MaskIterator< T, true > const_iterator
the iterator on the constant items
Definition RingDeque.h:226
const T & operator[](std::size_t i) const
the item of rank from the front, constant
void shrink_to_fit(void)
the least number of places, a power of 2 and 8 at least, that holds the items, the items moved there...
~RingDeque()
destroys the items and frees the places
void rotate(std::size_t r)
the item of rank moved to the rank , for every : time when the vector is full, the two counters alo...
void erase(std::size_t i)
removes the item of rank , moving by one place the items on the shorter side, in time (the remove( i...
void push_back(T &&v)
at the back, moved
Definition RingDeque.h:294
bool empty(void) const
true if there is no item, i.e., the two counters are equal
Definition RingDeque.h:254
RingDeque(std::initializer_list< T > l)
the items of l, in order
void pop_back(void)
removes the item at the back, moving back
#define ADS_RING_NOINLINE
the growth, never inlined
Definition RingDeque.h:91
#define ADS_RING_INLINE
the operations at the ends, inlined even where the compiler would not
Definition RingDeque.h:89