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

a double ended queue whose items are contiguous, rebuilt in the middle of its vector when they reach an end More...

#include <ADS/sequence/ContiguousDeque.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 = T *
 the iterator on the items
using const_iterator = const T *
 on the constant items
using reverse_iterator = std::reverse_iterator< iterator >
 the iterator on the items, backwards
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 the iterator on the constant items, backwards

Public member functions

 ContiguousDeque (void)=default
 the empty deque, with no places
 ContiguousDeque (std::initializer_list< T > l)
 the items of l, in order
 ContiguousDeque (const ContiguousDeque &o)
 a copy of o
 ContiguousDeque (ContiguousDeque &&o) noexcept
 the vector of o, which is left empty with no places
ContiguousDeque & operator= (ContiguousDeque o) noexcept
 the items of o, by copy and swap
 ~ContiguousDeque ()
 destroys the items and frees the places
void swap (ContiguousDeque &o) noexcept
 exchanges the vector with that of o
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 number \( c \) of places
T & operator[] (std::size_t i)
 the item of rank \( i \), \( A[ h + i ] \)
const T & operator[] (std::size_t i) const
 the item of rank \( i \), constant
T & front (void)
 the first item
T & back (void)
 the last item
T * data (void)
 the items, contiguous
const T * data (void) const
 the items, contiguous and constant
void insert (std::size_t i, const T &x)
 puts \( x \) at the rank \( i \), moving the items of the shorter side by one place, in \( O( 1 + \min\{ i , n - i \} ) \) amortized time
void erase (std::size_t i)
 removes the item of rank \( i \), moving the items of the shorter side by one place, in \( O( 1 + \min\{ i , n - i \} ) \) amortized time
void push_front (const T &x)
 \( x \) at the front, \( O( 1 ) \) amortized
void push_back (const T &x)
 \( x \) at the back, \( O( 1 ) \) amortized
void pop_front (void)
 removes the first item
void pop_back (void)
 removes the last item
void clear (void)
 removes all the items, the places kept
bool operator== (const ContiguousDeque &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
reverse_iterator rbegin (void)
 the iterator on the last item, backwards
reverse_iterator rend (void)
 the iterator before the first item, backwards

Detailed description

template<class T>
class ADS::ContiguousDeque< T >

a double ended queue whose items are contiguous, rebuilt in the middle of its vector when they reach an end

Member typedef documentation

◆ const_iterator

template<class T>
using ADS::ContiguousDeque< T >::const_iterator = const T *

on the constant items

◆ const_reference

template<class T>
using ADS::ContiguousDeque< T >::const_reference = const T &

a constant reference

◆ const_reverse_iterator

template<class T>
using ADS::ContiguousDeque< T >::const_reverse_iterator = std::reverse_iterator< const_iterator >

the iterator on the constant items, backwards

◆ difference_type

template<class T>
using ADS::ContiguousDeque< T >::difference_type = std::ptrdiff_t

the type of the distances

◆ iterator

template<class T>
using ADS::ContiguousDeque< T >::iterator = T *

the iterator on the items

◆ reference

template<class T>
using ADS::ContiguousDeque< T >::reference = T &

a reference to an item

◆ reverse_iterator

template<class T>
using ADS::ContiguousDeque< T >::reverse_iterator = std::reverse_iterator< iterator >

the iterator on the items, backwards

◆ size_type

template<class T>
using ADS::ContiguousDeque< T >::size_type = std::size_t

the type of the sizes

◆ value_type

template<class T>
using ADS::ContiguousDeque< T >::value_type = T

the type of the items

Constructor and destructor documentation

◆ ContiguousDeque() [1/4]

template<class T>
ADS::ContiguousDeque< T >::ContiguousDeque ( void )
default

the empty deque, with no places

◆ ContiguousDeque() [2/4]

template<class T>
ADS::ContiguousDeque< T >::ContiguousDeque ( std::initializer_list< T > l)

the items of l, in order

◆ ContiguousDeque() [3/4]

template<class T>
ADS::ContiguousDeque< T >::ContiguousDeque ( const ContiguousDeque< T > & o)

a copy of o

◆ ContiguousDeque() [4/4]

template<class T>
ADS::ContiguousDeque< T >::ContiguousDeque ( ContiguousDeque< T > && o)
noexcept

the vector of o, which is left empty with no places

◆ ~ContiguousDeque()

template<class T>
ADS::ContiguousDeque< T >::~ContiguousDeque ( )

destroys the items and frees the places

Member function documentation

◆ back()

template<class T>
T & ADS::ContiguousDeque< T >::back ( void )
inlinenodiscard

the last item

Precondition
the deque is not empty

◆ begin() [1/2]

template<class T>
iterator ADS::ContiguousDeque< T >::begin ( void )
inlinenodiscard

the iterator on the first item

◆ begin() [2/2]

template<class T>
const_iterator ADS::ContiguousDeque< T >::begin ( void ) const
inlinenodiscard

the constant iterator on the first item

◆ capacity()

template<class T>
std::size_t ADS::ContiguousDeque< T >::capacity ( void ) const
inlinenodiscard

the number \( c \) of places

◆ clear()

template<class T>
void ADS::ContiguousDeque< T >::clear ( void )

removes all the items, the places kept

◆ data() [1/2]

template<class T>
T * ADS::ContiguousDeque< T >::data ( void )
inlinenodiscard

the items, contiguous

◆ data() [2/2]

template<class T>
const T * ADS::ContiguousDeque< T >::data ( void ) const
inlinenodiscard

the items, contiguous and constant

◆ empty()

template<class T>
bool ADS::ContiguousDeque< T >::empty ( void ) const
inlinenodiscard

true if there is no item

◆ end() [1/2]

template<class T>
iterator ADS::ContiguousDeque< T >::end ( void )
inlinenodiscard

the iterator past the last item

◆ end() [2/2]

template<class T>
const_iterator ADS::ContiguousDeque< T >::end ( void ) const
inlinenodiscard

the constant iterator past the last item

◆ erase()

template<class T>
void ADS::ContiguousDeque< T >::erase ( std::size_t i)

removes the item of rank \( i \), moving the items of the shorter side by one place, in \( O( 1 + \min\{ i , n - i \} ) \) amortized time

In pseudocode (Morin, exercise 2.8):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{erase}( i ) \cr 2 & \quad \textbf{if}\ i < n / 2\ \textbf{then}\ A[ h + 1 .. h + i ] \gets A[ h .. h + i - 1 ];\ h \gets h + 1 \cr 3 & \quad \textbf{else}\ A[ h + i .. h + n - 2 ] \gets A[ h + i + 1 .. h + n - 1 ] \cr 4 & \quad n \gets n - 1 \cr 5 & \quad \textbf{if}\ c > 9 n + 24\ \textbf{then}\ \mathrm{rebuild}() \end{array}} \]

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

◆ front()

template<class T>
T & ADS::ContiguousDeque< T >::front ( void )
inlinenodiscard

the first item

Precondition
the deque is not empty

◆ insert()

template<class T>
void ADS::ContiguousDeque< T >::insert ( std::size_t i,
const T & x )

puts \( x \) at the rank \( i \), moving the items of the shorter side by one place, in \( O( 1 + \min\{ i , n - i \} ) \) amortized time

In pseudocode (Morin, exercise 2.8), \( A[ 0 .. c - 1 ] \) the vector:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{insert}( i , x ) \cr 2 & \quad \textbf{if}\ i < n / 2\ \textbf{then} \cr 3 & \qquad \textbf{if}\ h = 0\ \textbf{then}\ \mathrm{rebuild}() \cr 4 & \qquad A[ h - 1 .. h + i - 2 ] \gets A[ h .. h + i - 1 ]; \ h \gets h - 1 \cr 5 & \quad \textbf{else} \cr 6 & \qquad \textbf{if}\ h + n = c\ \textbf{then}\ \mathrm{rebuild}() \cr 7 & \qquad A[ h + i + 1 .. h + n ] \gets A[ h + i .. h + n - 1 ] \cr 8 & \quad A[ h + i ] \gets x;\ n \gets n + 1 \end{array}} \]

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

◆ operator=()

template<class T>
ContiguousDeque & ADS::ContiguousDeque< T >::operator= ( ContiguousDeque< T > o)
noexcept

the items of o, by copy and swap

◆ operator==()

template<class T>
bool ADS::ContiguousDeque< T >::operator== ( const ContiguousDeque< T > & o) const
inlinenodiscard

the same items in the same order

◆ operator[]() [1/2]

template<class T>
T & ADS::ContiguousDeque< T >::operator[] ( std::size_t i)
inlinenodiscard

the item of rank \( i \), \( A[ h + i ] \)

Precondition
\( i < n \)

◆ operator[]() [2/2]

template<class T>
const T & ADS::ContiguousDeque< T >::operator[] ( std::size_t i) const
inlinenodiscard

the item of rank \( i \), constant

Precondition
\( i < n \)

◆ pop_back()

template<class T>
void ADS::ContiguousDeque< T >::pop_back ( void )
inline

removes the last item

Precondition
the deque is not empty

◆ pop_front()

template<class T>
void ADS::ContiguousDeque< T >::pop_front ( void )
inline

removes the first item

Precondition
the deque is not empty

◆ push_back()

template<class T>
void ADS::ContiguousDeque< T >::push_back ( const T & x)

\( x \) at the back, \( O( 1 ) \) amortized

◆ push_front()

template<class T>
void ADS::ContiguousDeque< T >::push_front ( const T & x)

\( x \) at the front, \( O( 1 ) \) amortized

◆ rbegin()

template<class T>
reverse_iterator ADS::ContiguousDeque< T >::rbegin ( void )
inlinenodiscard

the iterator on the last item, backwards

◆ rend()

template<class T>
reverse_iterator ADS::ContiguousDeque< T >::rend ( void )
inlinenodiscard

the iterator before the first item, backwards

◆ size()

template<class T>
std::size_t ADS::ContiguousDeque< T >::size ( void ) const
inlinenodiscard

the number \( n \) of items

◆ swap()

template<class T>
void ADS::ContiguousDeque< T >::swap ( ContiguousDeque< T > & o)
noexcept

exchanges the vector with that of o


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