ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
UniqueQueue.h File Reference

A QUEUE [see ADT.h] with no duplicates, beyond the book, with one of two policies for an item that is already in the queue: IGNORE_NEW does not enqueue it again, FORGET_OLD removes the old copy and enqueues the item at the back. More...

#include "ADS/Contract.h"
#include "ADS/sequence/List.h"
#include <concepts>
#include <cstddef>
#include "ADS/queue/impl/UniqueQueue.tpp"

Go to the source code of this file.

Classes

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 More...

Namespaces

namespace  ADS

Enumerations

enum class  ADS::Duplicate { ADS::Duplicate::IGNORE_NEW , ADS::Duplicate::FORGET_OLD }
 what enqueue() does with an item already in the queue More...

Detailed description

A QUEUE [see ADT.h] with no duplicates, beyond the book, with one of two policies for an item that is already in the queue: IGNORE_NEW does not enqueue it again, FORGET_OLD removes the old copy and enqueues the item at the back.

The items are kept in a List [see List.h], so that enqueue() takes \( O( n ) \) time for the search of the copy and the other operations \( O( 1 ) \).

The contracts [see Contract.h]: top() and dequeue() need a queue that is not empty; enqueue() ensures that the item is in the queue, at the back with FORGET_OLD; the invariant is that no item occurs twice. The operations are defined in UniqueQueue.tpp.

See also
A. Montresor, Algoritmi e Strutture Dati, 2025, section 4.3, https://algoritmicamente.it/materiali/libro/capitoli/cap04.pdf
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa