62#ifndef __ADS_CubishArrayStack
63 #define __ADS_CubishArrayStack
75#include <initializer_list>
129 [[nodiscard]]
bool empty(
void )
const {
return( f_n == 0 ); }
132 [[nodiscard]] std::size_t
size(
void )
const {
return( f_n ); }
135 [[nodiscard]] std::size_t
block(
void )
const {
return( f_b ); }
144 return( at( f_mids[ i >> ( 2 * f_lg ) ] , i & ( f_b * f_b - 1 ) ) );
151 return( at( f_mids[ i >> ( 2 * f_lg ) ] , i & ( f_b * f_b - 1 ) ) );
176 void insert( std::size_t i ,
const T & x );
205 const std::size_t i = rankOf( p );
207 return(
begin() + std::ptrdiff_t( i ) );
213 template< std::input_iterator I , std::sentinel_for< I > E >
215 const std::size_t i0 = rankOf( p );
216 for( std::size_t i = i0 ; first != last ; ++first )
217 insert( i++ , T( *first ) );
218 return(
begin() + std::ptrdiff_t( i0 ) );
222 template<
class... A >
224 return(
insert( p , T( std::forward< A >( a )... ) ) );
231 const std::size_t i = rankOf( p );
233 return(
begin() + std::ptrdiff_t( i ) );
239 const std::size_t i = rankOf( first );
240 for( std::size_t k = rankOf( last ) - i ; k > 0 ; --k )
242 return(
begin() + std::ptrdiff_t( i ) );
279 return( std::size_t( p -
begin() ) );
285 std::unique_ptr< T[] > a;
292 std::unique_ptr< Leaf[] > L;
293 std::size_t head = 0;
300 Leaf & leaf(
const Mid & M , std::size_t j )
const {
301 return( M.L[ ( M.head + j ) & ( 2 * f_b - 1 ) ] );
305 T & at(
const Mid & M , std::size_t r )
const {
306 const std::size_t v = M.g + r;
307 const Leaf & f = leaf( M , v >> f_lg );
308 return( f.a[ ( f.off + v ) & ( f_b - 1 ) ] );
312 [[nodiscard]] Mid newMid(
void )
const;
315 std::unique_ptr< T[] > newLeaf(
void );
318 void freeLeaf( std::unique_ptr< T[] > a );
321 void reset( Mid & M );
324 void pushFront( Mid & M , T && x );
327 void pushBack( Mid & M , T && x );
330 T popFront( Mid & M );
333 T popBack( Mid & M );
338 void insert( Mid & M , std::size_t r , T && x );
341 void erase( Mid & M , std::size_t r );
345 void rebuild( std::size_t n );
348 [[nodiscard]]
bool full(
void )
const;
350 std::vector< Mid > f_mids;
351 std::vector< std::unique_ptr< T[] > > f_spare;
353 std::size_t f_b = 16;
366#include "ADS/sequence/impl/CubishArrayStack.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The iterators that the containers of the library have in common, beyond the book: they give a contain...
CubishArrayStack & operator=(CubishArrayStack o) noexcept
the items of o, by copy and swap
T value_type
the type of the items
Definition CubishArrayStack.h:100
iterator emplace(const_iterator p, A &&... a)
an item built from before the item of
Definition CubishArrayStack.h:223
std::size_t size_type
the type of the sizes
Definition CubishArrayStack.h:101
void pop_back(void)
removes the last item
Definition CubishArrayStack.h:250
iterator insert(const_iterator p, I first, E last)
the items of before the item of , in their order, one insert( i , x ) each; an iterator on the first...
Definition CubishArrayStack.h:214
iterator insert(const_iterator p, const T &x)
before the item of , i.e., insert( i , x ) with the rank of : the members by iterator of a SequenceC...
Definition CubishArrayStack.h:204
bool operator==(const CubishArrayStack &o) const
the same items in the same order
iterator end(void)
the iterator past the last item
Definition CubishArrayStack.h:261
const_iterator cend(void) const
the constant iterator past the last item
Definition CubishArrayStack.h:273
const_iterator end(void) const
the constant iterator past the last item
Definition CubishArrayStack.h:267
void erase(std::size_t i)
removes the item of rank , in amortized time
iterator begin(void)
the iterator on the first item
Definition CubishArrayStack.h:259
const_iterator begin(void) const
the constant iterator on the first item
Definition CubishArrayStack.h:263
std::size_t size(void) const
the number of items
Definition CubishArrayStack.h:132
void swap(CubishArrayStack &o) noexcept
exchanges the blocks with those of o
const T & operator[](std::size_t i) const
the item of rank , constant
Definition CubishArrayStack.h:149
T & operator[](std::size_t i)
the item of rank
Definition CubishArrayStack.h:142
CubishArrayStack(std::initializer_list< T > l)
the items of l, in order
RankIterator< CubishArrayStack, T, true > const_iterator
the iterator on the constant items
Definition CubishArrayStack.h:108
iterator erase(const_iterator p)
the item of removed, i.e., erase( i ) with its rank; an iterator on the item after it
Definition CubishArrayStack.h:230
CubishArrayStack(void)=default
the empty list
const_iterator cbegin(void) const
the constant iterator on the first item
Definition CubishArrayStack.h:271
CubishArrayStack(CubishArrayStack &&o) noexcept
the blocks of o, which is left empty
void clear(void)
removes all the items and frees the leaves
bool empty(void) const
true if there is no item
Definition CubishArrayStack.h:129
std::ptrdiff_t difference_type
the type of the distances
Definition CubishArrayStack.h:102
const T & const_reference
a constant reference
Definition CubishArrayStack.h:104
CubishArrayStack(const CubishArrayStack &o)
a copy of o
void push_back(const T &x)
at the end, amortized
Definition CubishArrayStack.h:246
std::size_t block(void) const
the places of a leaf
Definition CubishArrayStack.h:135
std::size_t capacity(void) const
the places of the leaves, those kept for later included
iterator erase(const_iterator first, const_iterator last)
the items of removed, one erase( i ) each; an iterator on the item after them
Definition CubishArrayStack.h:238
void insert(std::size_t i, const T &x)
puts at the rank , in amortized time
T & reference
a reference to an item
Definition CubishArrayStack.h:103
RankIterator< CubishArrayStack, T, false > iterator
the iterator on the items
Definition CubishArrayStack.h:106
the random-access iterator on the items of a container C read by rank, c[ i ] the item ,...
Definition Iterators.h:392
#define ADS_PRE(cond)
[check]
Definition Contract.h:121