74#ifndef __ADS_TieredVector
75 #define __ADS_TieredVector
105template<
class T ,
class A = std::allocator< T > >
136 [[nodiscard]]
bool empty(
void )
const {
return( f_n == 0 ); }
139 [[nodiscard]] std::size_t
size(
void )
const {
return( f_n ); }
142 [[nodiscard]] std::size_t
block(
void )
const {
return( f_b ); }
146 return( f_blocks.size() * f_b );
156 const std::size_t j = f_g + i;
157 Block & k = f_blocks[ j >> f_lg ];
158 return( k.a[ ( k.off + j ) & ( f_b - 1 ) ] );
164 const std::size_t j = f_g + i;
165 const Block & k = f_blocks[ j >> f_lg ];
166 return( k.a[ ( k.off + j ) & ( f_b - 1 ) ] );
171 [[nodiscard]]
const T &
front(
void )
const {
return( ( *
this )[ 0 ] ); }
175 [[nodiscard]]
const T &
back(
void )
const {
176 return( ( *
this )[ f_n - 1 ] );
210 void insert( std::size_t i ,
const T & x );
260 template<
bool Const >
263 using Owner = std::conditional_t< Const ,
const TieredVector ,
274 using reference = std::conditional_t< Const , const T & , T & >;
276 using pointer = std::conditional_t< Const , const T * , T * >;
282 Iterator( Owner * v , std::size_t i ) : f_v( v ) , f_i( i ) { }
286 requires( Const && ! K )
344 Owner * f_v =
nullptr;
379 const std::size_t i = rankOf( p );
381 return(
begin() + std::ptrdiff_t( i ) );
387 template< std::input_iterator I , std::sentinel_for< I > E >
389 const std::size_t i0 = rankOf( p );
390 for( std::size_t i = i0 ; first != last ; ++first )
391 insert( i++ , T( *first ) );
392 return(
begin() + std::ptrdiff_t( i0 ) );
396 template<
class... Args >
398 return(
insert( p , T( std::forward< Args >( a )... ) ) );
405 const std::size_t i = rankOf( p );
407 return(
begin() + std::ptrdiff_t( i ) );
413 const std::size_t i = rankOf( first );
414 for( std::size_t k = rankOf( last ) - i ; k > 0 ; --k )
416 return(
begin() + std::ptrdiff_t( i ) );
423 return( std::size_t( p -
begin() ) );
429 static constexpr bool STD = detail::isStdAllocator< A >;
432 using Places = std::conditional_t< STD , std::unique_ptr< T[] > ,
433 detail::AllocArray< A , T > >;
442 using Blocks = detail::AllocVector< A , Block >;
446 [[nodiscard]] Blocks blocksOf( std::size_t k , std::size_t b )
const {
447 Blocks B( f_blocks.get_allocator() );
449 for( std::size_t i = 0 ; i < k ; ++i )
450 B.push_back( Block{ places( b ) } );
455 [[nodiscard]] Places places( std::size_t b )
const {
457 return( std::make_unique< T[] >( b ) );
459 return( Places( f_blocks.get_allocator() , b ) );
465 void rebuild( std::size_t n );
491 void insertFront( std::size_t i , T && x );
495 void eraseFront( std::size_t i );
499 void eraseBack( std::size_t i );
503 [[nodiscard]]
bool full(
void )
const;
508 std::size_t f_b = 64;
521#include "ADS/sequence/impl/TieredVector.tpp"
The rules of the allocator-aware containers of the standard ([container.reqmts], [allocator....
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
friend Iterator operator+(Iterator a, difference_type k)
Definition TieredVector.h:326
Iterator & operator+=(difference_type k)
items on
Definition TieredVector.h:320
friend Iterator operator+(difference_type k, Iterator a)
Definition TieredVector.h:329
T value_type
the type of the items
Definition TieredVector.h:270
std::conditional_t< Const, const T &, T & > reference
a reference to an item, constant if Const
Definition TieredVector.h:274
Iterator operator--(int)
to the previous item, returning the iterator before the step
Definition TieredVector.h:314
std::random_access_iterator_tag iterator_category
the category of the iterator, random access
Definition TieredVector.h:268
reference operator[](difference_type k) const
the item places on
Definition TieredVector.h:294
Iterator(void)=default
an iterator on no vector
std::conditional_t< Const, const T *, T * > pointer
a pointer to an item, constant if Const
Definition TieredVector.h:276
Iterator operator++(int)
to the next item, returning the iterator before the step
Definition TieredVector.h:308
pointer operator->(void) const
the address of the item
Definition TieredVector.h:292
std::ptrdiff_t difference_type
the type of the distances
Definition TieredVector.h:272
auto operator<=>(const Iterator &o) const
the order of the indices
Definition TieredVector.h:341
reference operator*(void) const
the item
Definition TieredVector.h:290
Iterator(Owner *v, std::size_t i)
on the item of index of the vector
Definition TieredVector.h:282
friend difference_type operator-(const Iterator &a, const Iterator &b)
Definition TieredVector.h:335
Iterator & operator--(void)
to the previous item
Definition TieredVector.h:303
bool operator==(const Iterator &o) const
equal on the same index
Definition TieredVector.h:339
friend class Iterator
Definition TieredVector.h:348
Iterator(const Iterator< K > &o)
the const iterator from the other one
Definition TieredVector.h:287
Iterator & operator-=(difference_type k)
items back
Definition TieredVector.h:325
friend Iterator operator-(Iterator a, difference_type k)
Definition TieredVector.h:332
Iterator & operator++(void)
to the next item
Definition TieredVector.h:298
T value_type
the type of the items
Definition TieredVector.h:112
Iterator< true > const_iterator
the iterator on the constant items
Definition TieredVector.h:354
const_iterator end(void) const
the constant iterator past the last item
Definition TieredVector.h:365
TieredVector(const A &alloc)
the empty sequence, its blocks from alloc
Definition TieredVector.h:126
T & reference
a reference to an item
Definition TieredVector.h:118
std::size_t capacity(void) const
the places of the blocks,
Definition TieredVector.h:145
iterator begin(void)
the iterator on the first item
Definition TieredVector.h:357
iterator erase(const_iterator p)
the item of removed, i.e., erase( i ) with its rank; an iterator on the item after it
Definition TieredVector.h:404
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 TieredVector.h:378
T & operator[](std::size_t i)
the item at the index , at the place of the block , the offset of the block
Definition TieredVector.h:154
void insert(std::size_t i, const T &x)
at the index , the items from one place on, or those before one place back if , in amortized time
std::ptrdiff_t difference_type
the type of the distances
Definition TieredVector.h:116
void pop_back(void)
removes the last item, erase( n - 1 )
Definition TieredVector.h:245
bool empty(void) const
true if there is no item
Definition TieredVector.h:136
void erase(std::size_t i)
removes the item at the index , the items after it one place back, or those before it one place on if...
const_iterator begin(void) const
the constant iterator on the first item
Definition TieredVector.h:361
void push_back(const T &x)
at the end, insert( n , x )
Definition TieredVector.h:241
iterator erase(const_iterator first, const_iterator last)
the items of removed, one erase( i ) each; an iterator on the item after them
Definition TieredVector.h:412
allocator_type get_allocator(void) const
the allocator of the blocks
Definition TieredVector.h:131
TieredVector(void)=default
the empty vector
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 TieredVector.h:388
std::size_t size_type
the type of the sizes
Definition TieredVector.h:114
const T & operator[](std::size_t i) const
the item at the index , constant
Definition TieredVector.h:162
iterator end(void)
the iterator past the last item
Definition TieredVector.h:359
const T & front(void) const
the first item
Definition TieredVector.h:171
std::size_t size(void) const
the number of items,
Definition TieredVector.h:139
const_iterator cbegin(void) const
the constant iterator on the first item
Definition TieredVector.h:369
void pop_front(void)
removes the first item, erase( 0 ), amortized
Definition TieredVector.h:252
std::size_t block(void) const
the places of a block
Definition TieredVector.h:142
void push_front(const T &x)
at the front, insert( 0 , x ), amortized
Definition TieredVector.h:248
A allocator_type
the type of the allocator
Definition TieredVector.h:129
const T & const_reference
a constant reference to an item
Definition TieredVector.h:120
Iterator< false > iterator
the iterator on the items
Definition TieredVector.h:352
const T & back(void) const
the last item
Definition TieredVector.h:175
const_iterator cend(void) const
the constant iterator past the last item
Definition TieredVector.h:371
iterator emplace(const_iterator p, Args &&... a)
an item built from before the item of
Definition TieredVector.h:397
void clear(void)
removes the items
#define ADS_PRE(cond)
[check]
Definition Contract.h:121