Program Listing for File UniqueQueue.h
↰ Return to documentation for file (ADS/queue/UniqueQueue.h)
/*--------------------------------------------------------------------------*/
/*--------------------------- File UniqueQueue.h ---------------------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*----------------------------- DEFINITIONS --------------------------------*/
/*--------------------------------------------------------------------------*/
#ifndef __ADS_UniqueQueue
#define __ADS_UniqueQueue
/* self-identification: #endif constant */
/*--------------------------------------------------------------------------*/
/*------------------------------ INCLUDES ----------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/Contract.h"
#include "ADS/sequence/List.h"
#include <concepts>
#include <cstddef>
/*--------------------------------------------------------------------------*/
/*--------------------------- NAMESPACE ------------------------------------*/
/*--------------------------------------------------------------------------*/
namespace ADS {
/*--------------------------------------------------------------------------*/
/*-------------------------- CLASS UniqueQueue -----------------------------*/
/*--------------------------------------------------------------------------*/
enum class Duplicate {
IGNORE_NEW ,
FORGET_OLD
};
template< std::equality_comparable T , Duplicate D = Duplicate::IGNORE_NEW >
class UniqueQueue {
/*--------------------------------------------------------------------------*/
public:
using Item = T;
[[nodiscard]] bool empty( void ) const;
void enqueue( const T & v );
T dequeue( void );
[[nodiscard]] const T & top( void ) const;
[[nodiscard]] bool contains( const T & v ) const;
[[nodiscard]] std::size_t size( void ) const;
/*------------------------- THE STANDARD INTERFACE -------------------------*/
// a constant view of the items from the front to the back, bidirectional;
// a change through it could break the uniqueness
using value_type = T;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
using reference = const T &;
using const_reference = const T &;
using iterator = typename List< T >::const_iterator;
using const_iterator = typename List< T >::const_iterator;
[[nodiscard]] const_iterator begin( void ) const { return( f_L.begin() ); }
[[nodiscard]] const_iterator end( void ) const { return( f_L.end() ); }
[[nodiscard]] const_iterator cbegin( void ) const { return( begin() ); }
[[nodiscard]] const_iterator cend( void ) const { return( end() ); }
/*--------------------------------------------------------------------------*/
private:
[[nodiscard]] bool unique( void ) const;
[[nodiscard]] typename List< T >::Pos find( const T & v ) const;
List< T > f_L;
std::size_t f_size = 0;
}; // end( class UniqueQueue )
/*--------------------------------------------------------------------------*/
} // end( namespace ADS )
/*--------------------------------------------------------------------------*/
/*-------------------------- IMPLEMENTATION --------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/queue/impl/UniqueQueue.tpp"
/*--------------------------------------------------------------------------*/
#endif /* UniqueQueue.h included */
/*--------------------------------------------------------------------------*/
/*------------------------- End File UniqueQueue.h -------------------------*/
/*--------------------------------------------------------------------------*/