|
| | Treque (void)=default |
| | the empty treque
|
| | Treque (std::initializer_list< T > l) |
| | the items of l, in order
|
| bool | empty (void) const |
| | true if there is no item
|
| std::size_t | size (void) const |
| | the number \( n \) of items
|
| T & | operator[] (std::size_t i) |
| | the item of rank \( i \), in \( L \) or in \( R \)
|
| 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 \), in \( O( 1 + \min\{ i , n - i , | n / 2 - i | \} ) \) amortized time
|
| void | erase (std::size_t i) |
| | removes the item of rank \( i \), in \( O( 1 + \min\{ i , n - i , | n / 2 - i | \} ) \) 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... A> |
| iterator | emplace (const_iterator p, A &&... 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_front (const T &x) |
| | \( x \) at the front
|
| void | push_back (const T &x) |
| | \( x \) at the back
|
| void | pop_front (void) |
| | removes the first item
|
| void | pop_back (void) |
| | removes the last item
|
| void | clear (void) |
| | removes all the items
|
| bool | operator== (const Treque &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
|
template<class T>
class ADS::Treque< T >
a LIST by rank fast at both ends and in the middle, on two circular deques
removes the item of rank \( i \), in \( O( 1 + \min\{ i , n - i , | n / 2 - i | \} ) \) time
In pseudocode (Morin, exercise 2.3):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{erase}( i ) \cr
2 & \quad \textbf{if}\ i < |L|\ \textbf{then}\ L.\mathrm{erase}( i )
\ \textbf{else}\ R.\mathrm{erase}( i - |L| ) \cr
3 & \quad \mathrm{balance}()
\end{array}}
\]
- Precondition
- \( i < n \)
- Postcondition
- one item less
template<class T>
| void ADS::Treque< T >::insert |
( |
std::size_t | i, |
|
|
const T & | x ) |
puts \( x \) at the rank \( i \), in \( O( 1 + \min\{ i , n - i , | n / 2 - i | \} ) \) amortized time
In pseudocode (Morin, exercise 2.3), \( L \) and \( R \) the two deques:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{insert}( i , x ) \cr
2 & \quad \textbf{if}\ i < |L|\ \textbf{then}\ L.\mathrm{insert}( i , x
)\ \textbf{else}\ R.\mathrm{insert}( i - |L| , x ) \cr
3 & \quad \mathrm{balance}()
\end{array}}
\]
- Precondition
- \( i \le n \)
- Postcondition
- one item more, \( x \) at the rank \( i \)