ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::DualArrayDeque< T, S > Class Template Reference

a LIST by rank on two stacks S back to back, balanced More...

#include <ADS/sequence/DualArrayDeque.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< DualArrayDeque , T , false >
 the iterator on the items
using const_iterator = RankIterator< DualArrayDeque , T , true >
 the iterator on the constant items

Public member functions

 DualArrayDeque (void)=default
 the empty deque
 DualArrayDeque (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 \)
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 \} ) \) amortized time
void erase (std::size_t i)
 removes the item of rank \( i \), in \( O( 1 + \min\{ i , 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... 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, insert( 0 , x )
void push_back (const T &x)
 \( x \) at the back, insert( size() , x )
void pop_front (void)
 removes the first item
void pop_back (void)
 removes the last item
void rotate (std::size_t r)
 the item of rank \( i \) moved to the rank \( ( i + r ) \bmod n \), in \( O( 1 + \min\{ r , n - r \} ) \) amortized time (exercise 2.5 of Morin's book)
void clear (void)
 removes all the items
std::size_t frontSize (void) const
 the number of items of the front stack \( F \)
bool operator== (const DualArrayDeque &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

Detailed description

template<class T, class S = std::vector< T >>
class ADS::DualArrayDeque< T, S >

a LIST by rank on two stacks S back to back, balanced

Member typedef documentation

◆ const_iterator

template<class T, class S = std::vector< T >>
using ADS::DualArrayDeque< T, S >::const_iterator = RankIterator< DualArrayDeque , T , true >

the iterator on the constant items

◆ const_reference

template<class T, class S = std::vector< T >>
using ADS::DualArrayDeque< T, S >::const_reference = const T &

a constant reference

◆ difference_type

template<class T, class S = std::vector< T >>
using ADS::DualArrayDeque< T, S >::difference_type = std::ptrdiff_t

the type of the distances

◆ iterator

template<class T, class S = std::vector< T >>
using ADS::DualArrayDeque< T, S >::iterator = RankIterator< DualArrayDeque , T , false >

the iterator on the items

◆ reference

template<class T, class S = std::vector< T >>
using ADS::DualArrayDeque< T, S >::reference = T &

a reference to an item

◆ size_type

template<class T, class S = std::vector< T >>
using ADS::DualArrayDeque< T, S >::size_type = std::size_t

the type of the sizes

◆ value_type

template<class T, class S = std::vector< T >>
using ADS::DualArrayDeque< T, S >::value_type = T

the type of the items

Constructor and destructor documentation

◆ DualArrayDeque() [1/2]

template<class T, class S = std::vector< T >>
ADS::DualArrayDeque< T, S >::DualArrayDeque ( void )
default

the empty deque

◆ DualArrayDeque() [2/2]

template<class T, class S = std::vector< T >>
ADS::DualArrayDeque< T, S >::DualArrayDeque ( std::initializer_list< T > l)

the items of l, in order

Member function documentation

◆ back()

template<class T, class S = std::vector< T >>
const T & ADS::DualArrayDeque< T, S >::back ( void ) const
inlinenodiscard

the last item

Precondition
the deque is not empty

◆ begin() [1/2]

template<class T, class S = std::vector< T >>
iterator ADS::DualArrayDeque< T, S >::begin ( void )
inlinenodiscard

the iterator on the first item

◆ begin() [2/2]

template<class T, class S = std::vector< T >>
const_iterator ADS::DualArrayDeque< T, S >::begin ( void ) const
inlinenodiscard

the constant iterator on the first item

◆ cbegin()

template<class T, class S = std::vector< T >>
const_iterator ADS::DualArrayDeque< T, S >::cbegin ( void ) const
inlinenodiscard

the constant iterator on the first item

◆ cend()

template<class T, class S = std::vector< T >>
const_iterator ADS::DualArrayDeque< T, S >::cend ( void ) const
inlinenodiscard

the constant iterator past the last item

◆ clear()

template<class T, class S = std::vector< T >>
void ADS::DualArrayDeque< T, S >::clear ( void )

removes all the items

◆ emplace()

template<class T, class S = std::vector< T >>
template<class... A>
iterator ADS::DualArrayDeque< T, S >::emplace ( const_iterator p,
A &&... a )
inline

an item built from \( a \) before the item of \( p \)

◆ empty()

template<class T, class S = std::vector< T >>
bool ADS::DualArrayDeque< T, S >::empty ( void ) const
inlinenodiscard

true if there is no item

◆ end() [1/2]

template<class T, class S = std::vector< T >>
iterator ADS::DualArrayDeque< T, S >::end ( void )
inlinenodiscard

the iterator past the last item

◆ end() [2/2]

template<class T, class S = std::vector< T >>
const_iterator ADS::DualArrayDeque< T, S >::end ( void ) const
inlinenodiscard

the constant iterator past the last item

◆ erase() [1/3]

template<class T, class S = std::vector< T >>
iterator ADS::DualArrayDeque< T, S >::erase ( const_iterator first,
const_iterator last )
inline

the items of \( [ \mathit{first} , \mathit{last} ) \) removed, one erase( i ) each; an iterator on the item after them

◆ erase() [2/3]

template<class T, class S = std::vector< T >>
iterator ADS::DualArrayDeque< T, S >::erase ( const_iterator p)
inline

the item of \( p \) removed, i.e., erase( i ) with \( i \) its rank; an iterator on the item after it

Precondition
\( p \) is an iterator on an item of this sequence

◆ erase() [3/3]

template<class T, class S = std::vector< T >>
void ADS::DualArrayDeque< T, S >::erase ( std::size_t i)

removes the item of rank \( i \), in \( O( 1 + \min\{ i , n - i \} ) \) amortized time

In pseudocode (Morin, section 2.5):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{erase}( i ) \cr 2 & \quad \textbf{if}\ i < |F|\ \textbf{then}\ F.\mathrm{erase}( |F| - 1 - i ) \cr 3 & \quad \textbf{else}\ B.\mathrm{erase}( i - |F| ) \cr 4 & \quad \mathrm{balance}() \end{array}} \]

Precondition
\( i < n \)
Postcondition
one item less

◆ front()

template<class T, class S = std::vector< T >>
const T & ADS::DualArrayDeque< T, S >::front ( void ) const
inlinenodiscard

the first item

Precondition
the deque is not empty

◆ frontSize()

template<class T, class S = std::vector< T >>
std::size_t ADS::DualArrayDeque< T, S >::frontSize ( void ) const
inlinenodiscard

the number of items of the front stack \( F \)

◆ insert() [1/3]

template<class T, class S = std::vector< T >>
iterator ADS::DualArrayDeque< T, S >::insert ( const_iterator p,
const T & x )
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 \)

Precondition
\( p \) is an iterator of this sequence or its end

◆ insert() [2/3]

template<class T, class S = std::vector< T >>
template<std::input_iterator I, std::sentinel_for< I > E>
iterator ADS::DualArrayDeque< T, S >::insert ( const_iterator p,
I first,
E last )
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

◆ insert() [3/3]

template<class T, class S = std::vector< T >>
void ADS::DualArrayDeque< T, S >::insert ( std::size_t i,
const T & x )

puts \( x \) at the rank \( i \), in \( O( 1 + \min\{ i , n - i \} ) \) amortized time

In pseudocode (Morin, section 2.5), \( F \) and \( B \) the stacks:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{insert}( i , x ) \cr 2 & \quad \textbf{if}\ i < |F|\ \textbf{then}\ F.\mathrm{insert}( |F| - i , x ) \cr 3 & \quad \textbf{else}\ B.\mathrm{insert}( i - |F| , x ) \cr 4 & \quad \mathrm{balance}() \end{array}} \]

Precondition
\( i \le n \)
Postcondition
one item more, \( x \) at the rank \( i \)

◆ operator==()

template<class T, class S = std::vector< T >>
bool ADS::DualArrayDeque< T, S >::operator== ( const DualArrayDeque< T, S > & o) const
nodiscard

the same items in the same order

◆ operator[]() [1/2]

template<class T, class S = std::vector< T >>
T & ADS::DualArrayDeque< T, S >::operator[] ( std::size_t i)
nodiscard

the item of rank \( i \)

Precondition
\( i < n \)

◆ operator[]() [2/2]

template<class T, class S = std::vector< T >>
const T & ADS::DualArrayDeque< T, S >::operator[] ( std::size_t i) const
nodiscard

the item of rank \( i \), constant

Precondition
\( i < n \)

◆ pop_back()

template<class T, class S = std::vector< T >>
void ADS::DualArrayDeque< T, S >::pop_back ( void )
inline

removes the last item

Precondition
the deque is not empty

◆ pop_front()

template<class T, class S = std::vector< T >>
void ADS::DualArrayDeque< T, S >::pop_front ( void )
inline

removes the first item

Precondition
the deque is not empty

◆ push_back()

template<class T, class S = std::vector< T >>
void ADS::DualArrayDeque< T, S >::push_back ( const T & x)
inline

\( x \) at the back, insert( size() , x )

◆ push_front()

template<class T, class S = std::vector< T >>
void ADS::DualArrayDeque< T, S >::push_front ( const T & x)
inline

\( x \) at the front, insert( 0 , x )

◆ rotate()

template<class T, class S = std::vector< T >>
void ADS::DualArrayDeque< T, S >::rotate ( std::size_t r)

the item of rank \( i \) moved to the rank \( ( i + r ) \bmod n \), in \( O( 1 + \min\{ r , n - r \} ) \) amortized time (exercise 2.5 of Morin's book)

In pseudocode (Morin, exercise 2.5), \( r \) reduced modulo \( n \):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{rotate}( r ) \cr 2 & \quad \textbf{if}\ r \le n - r\ \textbf{then}\ \textbf{repeat} \ r\ \text{ times: }\mathrm{insert}( 0 , \mathrm{erase}( n - 1 ) ) \cr 3 & \quad \textbf{else}\ \textbf{repeat}\ n - r\ \text{ times: } \mathrm{insert}( n - 1 , \mathrm{erase}( 0 ) ) \end{array}} \]

◆ size()

template<class T, class S = std::vector< T >>
std::size_t ADS::DualArrayDeque< T, S >::size ( void ) const
inlinenodiscard

the number \( n \) of items


The documentation for this class was generated from the following file: