|
ADS
Algorithms and Data Structures
|
a QUEUE with no duplicates; the equality of T must be an equivalence, so an item unequal to itself (e.g., a NaN) cannot be enqueued: the postcondition of enqueue() refuses it More...
#include <ADS/queue/UniqueQueue.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 = typename List< T >::const_iterator |
| a constant iterator of the list | |
| using | const_iterator = typename List< T >::const_iterator |
| a constant iterator of the list | |
Public member functions | |
| bool | empty (void) const |
| true if there is no item | |
| void | enqueue (const T &v) |
| puts \( v \) at the back, unless the policy keeps an old copy of it | |
| T | dequeue (void) |
| removes the item at the front and returns it | |
| const T & | top (void) const |
| the item at the front | |
| bool | contains (const T &v) const |
| whether \( v \) is in the queue, \( O( n ) \) | |
| std::size_t | size (void) const |
| the number of items, \( 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 with no duplicates; the equality of T must be an equivalence, so an item unequal to itself (e.g., a NaN) cannot be enqueued: the postcondition of enqueue() refuses it
| using ADS::UniqueQueue< T, D >::const_iterator = typename List< T >::const_iterator |
a constant iterator of the list
| using ADS::UniqueQueue< T, D >::const_reference = const T & |
a constant reference
| using ADS::UniqueQueue< T, D >::difference_type = std::ptrdiff_t |
the type of the distances
| using ADS::UniqueQueue< T, D >::Item = T |
the type of the items
| using ADS::UniqueQueue< T, D >::iterator = typename List< T >::const_iterator |
a constant iterator of the list
| using ADS::UniqueQueue< T, D >::reference = const T & |
a constant reference
| using ADS::UniqueQueue< T, D >::size_type = std::size_t |
the type of the sizes
| using ADS::UniqueQueue< T, D >::value_type = T |
the type of the items
|
inlinenodiscard |
the iterator on the item at the front
|
inlinenodiscard |
as begin()
|
inlinenodiscard |
as end()
|
nodiscard |
whether \( v \) is in the queue, \( O( n ) \)
| T ADS::UniqueQueue< T, D >::dequeue | ( | void | ) |
removes the item at the front and returns it
|
nodiscard |
true if there is no item
|
inlinenodiscard |
the iterator past the item at the back
| void ADS::UniqueQueue< T, D >::enqueue | ( | const T & | v | ) |
puts \( v \) at the back, unless the policy keeps an old copy of it
In pseudocode (section 4.3.1, beyond the book), \( L \) the list of the items:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{enqueue}( v ) \cr 2 & \quad p \gets \text{the position of } v \text{ in } L \text{, by a } \text{scan} \cr 3 & \quad \textbf{if not}\ L.\mathrm{finished}( p )\ \textbf{then} \cr 4 & \qquad \textbf{if}\ D = \text{IGNORE\_NEW}\ \textbf{then return} \cr 5 & \qquad L.\mathrm{remove}( p ) \cr 6 & \quad \text{append } v \text{ to } L \end{array}} \]
|
nodiscard |
the number of items, \( n \)
|
nodiscard |
the item at the front