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

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()

Detailed description

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
class ADS::UniqueQueue< T, D >

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

Member typedef documentation

◆ const_iterator

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
using ADS::UniqueQueue< T, D >::const_iterator = typename List< T >::const_iterator

a constant iterator of the list

◆ const_reference

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
using ADS::UniqueQueue< T, D >::const_reference = const T &

a constant reference

◆ difference_type

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
using ADS::UniqueQueue< T, D >::difference_type = std::ptrdiff_t

the type of the distances

◆ Item

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
using ADS::UniqueQueue< T, D >::Item = T

the type of the items

◆ iterator

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
using ADS::UniqueQueue< T, D >::iterator = typename List< T >::const_iterator

a constant iterator of the list

◆ reference

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
using ADS::UniqueQueue< T, D >::reference = const T &

a constant reference

◆ size_type

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
using ADS::UniqueQueue< T, D >::size_type = std::size_t

the type of the sizes

◆ value_type

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
using ADS::UniqueQueue< T, D >::value_type = T

the type of the items

Member function documentation

◆ begin()

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
const_iterator ADS::UniqueQueue< T, D >::begin ( void ) const
inlinenodiscard

the iterator on the item at the front

◆ cbegin()

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
const_iterator ADS::UniqueQueue< T, D >::cbegin ( void ) const
inlinenodiscard

as begin()

◆ cend()

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
const_iterator ADS::UniqueQueue< T, D >::cend ( void ) const
inlinenodiscard

as end()

◆ contains()

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
bool ADS::UniqueQueue< T, D >::contains ( const T & v) const
nodiscard

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

◆ dequeue()

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
T ADS::UniqueQueue< T, D >::dequeue ( void )

removes the item at the front and returns it

Precondition
the queue is not empty

◆ empty()

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
bool ADS::UniqueQueue< T, D >::empty ( void ) const
nodiscard

true if there is no item

◆ end()

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
const_iterator ADS::UniqueQueue< T, D >::end ( void ) const
inlinenodiscard

the iterator past the item at the back

◆ enqueue()

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
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}} \]

Postcondition
\( v \) is in the queue, at the back with FORGET_OLD

◆ size()

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
std::size_t ADS::UniqueQueue< T, D >::size ( void ) const
nodiscard

the number of items, \( n \)

◆ top()

template<std::equality_comparable T, Duplicate D = Duplicate::IGNORE_NEW>
const T & ADS::UniqueQueue< T, D >::top ( void ) const
nodiscard

the item at the front

Precondition
the queue is not empty

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