|
ADS
Algorithms and Data Structures
|
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() | |
a QUEUE realized with a circular vector of a given capacity
| using ADS::ArrayQueue< T >::const_iterator = CircularIterator< T > |
a constant iterator
| using ADS::ArrayQueue< T >::const_reference = const T & |
a constant reference
| using ADS::ArrayQueue< T >::difference_type = std::ptrdiff_t |
the type of the distances
| using ADS::ArrayQueue< T >::Item = T |
the type of the items
| using ADS::ArrayQueue< T >::iterator = CircularIterator< T > |
a constant iterator
| using ADS::ArrayQueue< T >::reference = const T & |
a constant reference
| using ADS::ArrayQueue< T >::size_type = std::size_t |
the type of the sizes
| using ADS::ArrayQueue< T >::value_type = T |
the type of the items
|
explicit |
the empty queue of at most \( \mathit{dim} \) items
| 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
|
noexcept |
the items of other, which is left empty with no capacity
|
inlinenodiscard |
the iterator on the item at the front
|
nodiscard |
the maximum number of items, \( m \)
|
inlinenodiscard |
as begin()
|
inlinenodiscard |
as end()
|
nodiscard |
whether \( v \) is in the queue, \( O( n ) \)
| 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}} \]
|
nodiscard |
true if there is no item, i.e., \( n = 0 \)
|
inlinenodiscard |
the iterator past the item at the back
| 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}} \]
|
noexcept |
the items of other, by copy and swap
|
nodiscard |
the number of items, \( n \)
|
noexcept |
exchanges the items and the capacities with other
|
nodiscard |
the item at the front, \( A[ h ] \)