|
ADS
Algorithms and Data Structures
|
a LIST by rank on blocks of \( 1 , 2 , \ldots , r \) places, with \( O( \sqrt{n} ) \) places wasted More...
#include <ADS/sequence/RootishArrayStack.h>
Public types | |
| using | value_type = T |
| the type of the items | |
| using | size_type = std::size_t |
| the type of the sizes | |
| using | difference_type = std::ptrdiff_t |
| the type of the distances | |
| using | reference = T & |
| a reference to an item | |
| using | const_reference = const T & |
| a constant reference | |
| using | iterator = RankIterator< RootishArrayStack , T , false > |
| the iterator on the items | |
| using | const_iterator = RankIterator< RootishArrayStack , T , true > |
| the iterator on the constant items | |
| using | allocator_type = A |
| the type of the allocator | |
Public member functions | |
| allocator_type | get_allocator (void) const |
| the allocator of the blocks | |
| RootishArrayStack (void)=default | |
| the empty list, with no block | |
| RootishArrayStack (const A &alloc) | |
| the empty sequence, its blocks from alloc | |
| RootishArrayStack (std::initializer_list< T > l) | |
| the items of l, in order | |
| RootishArrayStack (const RootishArrayStack &o) | |
| a copy of o, on the allocator that select_on_container_copy_construction() gives | |
| RootishArrayStack (const RootishArrayStack &o, const A &alloc) | |
| a copy of o, on alloc | |
| RootishArrayStack (RootishArrayStack &&o) noexcept | |
| the blocks of o, which is left empty | |
| RootishArrayStack (RootishArrayStack &&o, const A &alloc) | |
| the items of o, which is left empty, on alloc: its blocks if the allocators are equal, else its items moved one by one | |
| RootishArrayStack & | operator= (RootishArrayStack o) noexcept |
| the items of o, by copy and swap, when the allocators are all equal | |
| RootishArrayStack & | operator= (const RootishArrayStack &o) |
| the copy assignment, with the allocator of o if it propagates | |
| RootishArrayStack & | operator= (RootishArrayStack &&o) |
| the move assignment: the memory of o if its allocator propagates or is equal, else its items moved one by one | |
| ~RootishArrayStack () | |
| destroys the items and frees the blocks | |
| void | swap (RootishArrayStack &o) noexcept(detail::swapNoexcept< A >) |
| exchanges the blocks with those of o, and the allocators if they propagate on a swap | |
| bool | empty (void) const |
| true if there is no item | |
| std::size_t | size (void) const |
| the number \( n \) of items | |
| std::size_t | capacity (void) const |
| the places of the \( r \) blocks, \( r ( r + 1 ) / 2 \) | |
| std::size_t | blocks (void) const |
| the number \( r \) of blocks | |
| T & | operator[] (std::size_t i) |
| the item of rank \( i \), in the block \( b( i ) \) of (1) | |
| const T & | operator[] (std::size_t i) const |
| the item of rank \( i \), constant | |
| const T & | front (void) const |
| the first item | |
| const T & | back (void) const |
| the last item | |
| void | insert (std::size_t i, const T &x) |
| puts \( x \) at the rank \( i \), the items from \( i \) one rank on, in \( O( 1 + n - i ) \) amortized time | |
| void | erase (std::size_t i) |
| removes the item of rank \( i \), those after it one rank back, in \( O( 1 + n - i ) \) amortized time | |
| iterator | insert (const_iterator p, const T &x) |
| \( x \) before the item of \( p \), i.e., insert( i , x ) with \( i \) the rank of \( p \): the members by iterator of a SequenceContainer of the standard library, by which std::flat_set and std::flat_map keep their keys here; an iterator on \( x \) | |
| template<std::input_iterator I, std::sentinel_for< I > E> | |
| iterator | insert (const_iterator p, I first, E last) |
| the items of \( [ \mathit{first} , \mathit{last} ) \) before the item of \( p \), in their order, one insert( i , x ) each; an iterator on the first of them | |
| template<class... Args> | |
| iterator | emplace (const_iterator p, Args &&... a) |
| an item built from \( a \) before the item of \( p \) | |
| iterator | erase (const_iterator p) |
| the item of \( p \) removed, i.e., erase( i ) with \( i \) its rank; an iterator on the item after it | |
| iterator | erase (const_iterator first, const_iterator last) |
| the items of \( [ \mathit{first} , \mathit{last} ) \) removed, one erase( i ) each; an iterator on the item after them | |
| void | push_back (const T &x) |
| \( x \) at the end, insert( size() , x ) | |
| void | push_back (T &&x) |
| \( x \) at the end, moved | |
| template<class... Args> | |
| T & | emplace_back (Args &&... args) |
| the item built from args at the end, \( O( 1 ) \) amortized | |
| void | pop_back (void) |
| removes the last item | |
| void | clear (void) |
| removes all the items and frees the blocks | |
| bool | operator== (const RootishArrayStack &o) const |
| the same items in the same order | |
| iterator | begin (void) |
| the iterator on the first item | |
| iterator | end (void) |
| the iterator past the last item | |
| const_iterator | begin (void) const |
| the constant iterator on the first item | |
| const_iterator | end (void) const |
| the constant iterator past the last item | |
| const_iterator | cbegin (void) const |
| the constant iterator on the first item | |
| const_iterator | cend (void) const |
| the constant iterator past the last item | |
Static public member functions | |
| static std::size_t | block (std::size_t i) |
| the block of the rank \( i \), (1) | |
a LIST by rank on blocks of \( 1 , 2 , \ldots , r \) places, with \( O( \sqrt{n} ) \) places wasted
| using ADS::RootishArrayStack< T, A >::allocator_type = A |
the type of the allocator
| using ADS::RootishArrayStack< T, A >::const_iterator = RankIterator< RootishArrayStack , T , true > |
the iterator on the constant items
| using ADS::RootishArrayStack< T, A >::const_reference = const T & |
a constant reference
| using ADS::RootishArrayStack< T, A >::difference_type = std::ptrdiff_t |
the type of the distances
| using ADS::RootishArrayStack< T, A >::iterator = RankIterator< RootishArrayStack , T , false > |
the iterator on the items
| using ADS::RootishArrayStack< T, A >::reference = T & |
a reference to an item
| using ADS::RootishArrayStack< T, A >::size_type = std::size_t |
the type of the sizes
| using ADS::RootishArrayStack< T, A >::value_type = T |
the type of the items
|
default |
the empty list, with no block
|
inlineexplicit |
the empty sequence, its blocks from alloc
| ADS::RootishArrayStack< T, A >::RootishArrayStack | ( | std::initializer_list< T > | l | ) |
the items of l, in order
| ADS::RootishArrayStack< T, A >::RootishArrayStack | ( | const RootishArrayStack< T, A > & | o | ) |
a copy of o, on the allocator that select_on_container_copy_construction() gives
| ADS::RootishArrayStack< T, A >::RootishArrayStack | ( | const RootishArrayStack< T, A > & | o, |
| const A & | alloc ) |
a copy of o, on alloc
|
noexcept |
the blocks of o, which is left empty
| ADS::RootishArrayStack< T, A >::RootishArrayStack | ( | RootishArrayStack< T, A > && | o, |
| const A & | alloc ) |
the items of o, which is left empty, on alloc: its blocks if the allocators are equal, else its items moved one by one
| ADS::RootishArrayStack< T, A >::~RootishArrayStack | ( | ) |
destroys the items and frees the blocks
|
nodiscard |
the last item
|
inlinenodiscard |
the iterator on the first item
|
inlinenodiscard |
the constant iterator on the first item
|
staticnodiscard |
the block of the rank \( i \), (1)
In pseudocode, the root in floating point corrected by two loops:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{block}( i ) \cr 2 & \quad b \gets \lceil ( -3 + \sqrt{ 9 + 8 i } ) / 2 \rceil \quad \triangleright\ \text{in } \mathtt{double} \cr 3 & \quad \textbf{while}\ b > 0\ \textbf{and}\ b ( b + 1 ) / 2 > i \ \textbf{do}\ b \gets b - 1 \cr 4 & \quad \textbf{while}\ ( b + 1 ) ( b + 2 ) / 2 \le i \ \textbf{do}\ b \gets b + 1 \cr 5 & \quad \textbf{return}\ b \end{array}} \]
|
inlinenodiscard |
the number \( r \) of blocks
|
inlinenodiscard |
the places of the \( r \) blocks, \( r ( r + 1 ) / 2 \)
|
inlinenodiscard |
the constant iterator on the first item
|
inlinenodiscard |
the constant iterator past the last item
| void ADS::RootishArrayStack< T, A >::clear | ( | void | ) |
removes all the items and frees the blocks
|
inline |
an item built from \( a \) before the item of \( p \)
| T & ADS::RootishArrayStack< T, A >::emplace_back | ( | Args &&... | args | ) |
the item built from args at the end, \( O( 1 ) \) amortized
|
inlinenodiscard |
true if there is no item
|
inlinenodiscard |
the iterator past the last item
|
inlinenodiscard |
the constant iterator past the last item
|
inline |
the items of \( [ \mathit{first} , \mathit{last} ) \) removed, one erase( i ) each; an iterator on the item after them
|
inline |
the item of \( p \) removed, i.e., erase( i ) with \( i \) its rank; an iterator on the item after it
| void ADS::RootishArrayStack< T, A >::erase | ( | std::size_t | i | ) |
removes the item of rank \( i \), those after it one rank back, in \( O( 1 + n - i ) \) amortized time
In pseudocode (Morin, section 2.6):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{erase}( i ) \cr 2 & \quad \textbf{for}\ k \gets i\ \textbf{to}\ n - 2\ \textbf{do} \ \mathrm{set}( k , \mathrm{get}( k + 1 ) ) \cr 3 & \quad n \gets n - 1 \cr 4 & \quad \textbf{while}\ r > 0\ \textbf{and}\ ( r - 2 ) ( r - 1 ) / 2 \ge n\ \textbf{do}\ \text{free } B_{r-1};\ r \gets r - 1 \end{array}} \]
|
nodiscard |
the first item
|
inlinenodiscard |
the allocator of the blocks
|
inline |
\( x \) before the item of \( p \), i.e., insert( i , x ) with \( i \) the rank of \( p \): the members by iterator of a SequenceContainer of the standard library, by which std::flat_set and std::flat_map keep their keys here; an iterator on \( x \)
|
inline |
the items of \( [ \mathit{first} , \mathit{last} ) \) before the item of \( p \), in their order, one insert( i , x ) each; an iterator on the first of them
| void ADS::RootishArrayStack< T, A >::insert | ( | std::size_t | i, |
| const T & | x ) |
puts \( x \) at the rank \( i \), the items from \( i \) one rank on, in \( O( 1 + n - i ) \) amortized time
In pseudocode (Morin, section 2.6), \( B \) the blocks:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{insert}( i , x ) \cr 2 & \quad \textbf{if}\ r ( r + 1 ) / 2 = n\ \textbf{then} \ \text{a new block } B_r \text{ of } r + 1 \text{ places}; \ r \gets r + 1 \cr 3 & \quad \textbf{for}\ k \gets n\ \textbf{downto}\ i + 1\ \textbf{do} \ \mathrm{set}( k , \mathrm{get}( k - 1 ) ) \cr 4 & \quad \mathrm{set}( i , x );\ n \gets n + 1 \end{array}} \]
|
inline |
the copy assignment, with the allocator of o if it propagates
|
inline |
the move assignment: the memory of o if its allocator propagates or is equal, else its items moved one by one
|
noexcept |
the items of o, by copy and swap, when the allocators are all equal
|
nodiscard |
the same items in the same order
|
nodiscard |
the item of rank \( i \), in the block \( b( i ) \) of (1)
|
nodiscard |
the item of rank \( i \), constant
|
inline |
removes the last item
|
inline |
\( x \) at the end, insert( size() , x )
|
inline |
\( x \) at the end, moved
|
inlinenodiscard |
the number \( n \) of items
|
noexcept |
exchanges the blocks with those of o, and the allocators if they propagate on a swap