Program Listing for File LinkedHashSet.h
↰ Return to documentation for file (ADS/set/LinkedHashSet.h)
/*--------------------------------------------------------------------------*/
/*-------------------------- File LinkedHashSet.h --------------------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*----------------------------- DEFINITIONS --------------------------------*/
/*--------------------------------------------------------------------------*/
#ifndef __ADS_LinkedHashSet
#define __ADS_LinkedHashSet
/* self-identification: #endif constant */
/*--------------------------------------------------------------------------*/
/*------------------------------ INCLUDES ----------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/Contract.h"
#include "ADS/dictionary/ChainedHashTable.h"
#include "ADS/sequence/List.h"
#include "ADS/set/SetOperations.h"
#include <algorithm>
#include <concepts>
#include <cstddef>
#include <functional>
#include <optional>
#include <stdexcept>
#include <utility>
#include <vector>
/*--------------------------------------------------------------------------*/
/*--------------------------- NAMESPACE ------------------------------------*/
/*--------------------------------------------------------------------------*/
namespace ADS {
/*--------------------------------------------------------------------------*/
/*-------------------------- CLASS LinkedHashSet ---------------------------*/
/*--------------------------------------------------------------------------*/
template< class T , class H = std::hash< T > >
class LinkedHashSet {
/*--------------------------------------------------------------------------*/
public:
using Item = T;
LinkedHashSet( void );
LinkedHashSet( const LinkedHashSet & o );
LinkedHashSet & operator=( const LinkedHashSet & ) = delete;
[[nodiscard]] std::size_t size( void ) const;
[[nodiscard]] bool empty( void ) const;
[[nodiscard]] bool contains( const T & x ) const;
void insert( const T & x );
void remove( const T & x );
template< class F >
void forEach( F && f ) const;
/*------------------------- THE STANDARD INTERFACE -------------------------*/
// a constant view of the items in the order of their insertion,
// bidirectional
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 const_iterator = typename List< T >::const_iterator;
using iterator = const_iterator;
[[nodiscard]] const_iterator begin( void ) const {
return( f_order.begin() );
}
[[nodiscard]] const_iterator end( void ) const { return( f_order.end() ); }
[[nodiscard]] const_iterator cbegin( void ) const { return( begin() ); }
[[nodiscard]] const_iterator cend( void ) const { return( end() ); }
/*--------------------------------------------------------------------------*/
private:
using Pos = typename List< T >::Pos;
[[nodiscard]] bool indexed( void ) const;
List< T > f_order;
ChainedHashTable< T , Pos , Chain::FRONT , H > f_index;
}; // end( class LinkedHashSet )
} // end( namespace ADS )
/*--------------------------------------------------------------------------*/
/*-------------------------- IMPLEMENTATION --------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/set/impl/LinkedHashSet.tpp"
/*--------------------------------------------------------------------------*/
#endif /* LinkedHashSet.h included */
/*--------------------------------------------------------------------------*/
/*------------------------ End File LinkedHashSet.h ------------------------*/
/*--------------------------------------------------------------------------*/