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

a QUEUE realized with a circular vector of a given capacity More...

#include <ADS/queue/ArrayQueue.h>

Public types

using Item = T
 the type of the items
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 = const T &
 a constant reference
using const_reference = const T &
 a constant reference
using iterator = CircularIterator< T >
 a constant iterator
using const_iterator = CircularIterator< T >
 a constant iterator

Public member functions

 ArrayQueue (std::size_t dim)
 the empty queue of at most \( \mathit{dim} \) items
 ArrayQueue (const ArrayQueue &other)
 a copy of other, item by item, from the place 0 of a vector of the same capacity
 ArrayQueue (ArrayQueue &&other) noexcept
 the items of other, which is left empty with no capacity
ArrayQueue & operator= (ArrayQueue other) noexcept
 the items of other, by copy and swap
void swap (ArrayQueue &other) noexcept
 exchanges the items and the capacities with other
bool empty (void) const
 true if there is no item, i.e., \( n = 0 \)
const T & top (void) const
 the item at the front, \( A[ h ] \)
T dequeue (void)
 removes the item at the front and returns it
void enqueue (const T &v)
 puts \( v \) at the back
std::size_t size (void) const
 the number of items, \( n \)
std::size_t capacity (void) const
 the maximum number of items, \( m \)
bool contains (const T &v) const
 whether \( v \) is in the queue, \( O( n ) \)
const_iterator begin (void) const
 the iterator on the item at the front
const_iterator end (void) const
 the iterator past the item at the back
const_iterator cbegin (void) const
 as begin()
const_iterator cend (void) const
 as end()

Detailed description

template<class T>
class ADS::ArrayQueue< T >

a QUEUE realized with a circular vector of a given capacity

Member typedef documentation

◆ const_iterator

template<class T>
using ADS::ArrayQueue< T >::const_iterator = CircularIterator< T >

a constant iterator

◆ const_reference

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

a constant reference

◆ difference_type

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

the type of the distances

◆ Item

template<class T>
using ADS::ArrayQueue< T >::Item = T

the type of the items

◆ iterator

template<class T>
using ADS::ArrayQueue< T >::iterator = CircularIterator< T >

a constant iterator

◆ reference

template<class T>
using ADS::ArrayQueue< T >::reference = const T &

a constant reference

◆ size_type

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

the type of the sizes

◆ value_type

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

the type of the items

Constructor and destructor documentation

◆ ArrayQueue() [1/3]

template<class T>
ADS::ArrayQueue< T >::ArrayQueue ( std::size_t dim)
explicit

the empty queue of at most \( \mathit{dim} \) items

◆ ArrayQueue() [2/3]

template<class T>
ADS::ArrayQueue< T >::ArrayQueue ( const ArrayQueue< T > & other)

a copy of other, item by item, from the place 0 of a vector of the same capacity

◆ ArrayQueue() [3/3]

template<class T>
ADS::ArrayQueue< T >::ArrayQueue ( ArrayQueue< T > && other)
noexcept

the items of other, which is left empty with no capacity

Member function documentation

◆ begin()

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

the iterator on the item at the front

◆ capacity()

template<class T>
std::size_t ADS::ArrayQueue< T >::capacity ( void ) const
nodiscard

the maximum number of items, \( m \)

◆ cbegin()

template<class T>
const_iterator ADS::ArrayQueue< T >::cbegin ( void ) const
inlinenodiscard

as begin()

◆ cend()

template<class T>
const_iterator ADS::ArrayQueue< T >::cend ( void ) const
inlinenodiscard

as end()

◆ contains()

template<class T>
bool ADS::ArrayQueue< T >::contains ( const T & v) const
nodiscard

whether \( v \) is in the queue, \( O( n ) \)

◆ dequeue()

template<class T>
T ADS::ArrayQueue< T >::dequeue ( void )

removes the item at the front and returns it

In pseudocode (section 4.3.3), \( A[ 0 .. m - 1 ] \) the circular vector:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{dequeue}()\quad \triangleright\ A[ h ] \text{ is the oldest item} \cr 2 & \quad t \gets A[ h ];\ n \gets n - 1;\ h \gets ( h + 1 ) \bmod m \cr 3 & \quad \textbf{return}\ t \end{array}} \]

Precondition
the queue is not empty
Postcondition
one item less

◆ empty()

template<class T>
bool ADS::ArrayQueue< T >::empty ( void ) const
nodiscard

true if there is no item, i.e., \( n = 0 \)

◆ end()

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

the iterator past the item at the back

◆ enqueue()

template<class T>
void ADS::ArrayQueue< T >::enqueue ( const T & v)

puts \( v \) at the back

In pseudocode (section 4.3.3):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{enqueue}( v ) \cr 2 & \quad A[ ( h + n ) \bmod m ] \gets v\quad \triangleright \ \text{the first free cell after the tail} \cr 3 & \quad n \gets n + 1 \end{array}} \]

Precondition
the queue is not full
Postcondition
one item more

◆ operator=()

template<class T>
ArrayQueue & ADS::ArrayQueue< T >::operator= ( ArrayQueue< T > other)
noexcept

the items of other, by copy and swap

◆ size()

template<class T>
std::size_t ADS::ArrayQueue< T >::size ( void ) const
nodiscard

the number of items, \( n \)

◆ swap()

template<class T>
void ADS::ArrayQueue< T >::swap ( ArrayQueue< T > & other)
noexcept

exchanges the items and the capacities with other

◆ top()

template<class T>
const T & ADS::ArrayQueue< T >::top ( void ) const
nodiscard

the item at the front, \( A[ h ] \)

Precondition
the queue is not empty

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