Program Listing for File DictionarySet.h
↰ Return to documentation for file (ADS/set/DictionarySet.h)
/*--------------------------------------------------------------------------*/
/*-------------------------- File DictionarySet.h --------------------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*----------------------------- DEFINITIONS --------------------------------*/
/*--------------------------------------------------------------------------*/
#ifndef __ADS_DictionarySet
#define __ADS_DictionarySet
/* self-identification: #endif constant */
/*--------------------------------------------------------------------------*/
/*------------------------------ INCLUDES ----------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/Contract.h"
#include "ADS/Iterators.h"
#include "ADS/dictionary/ChainedHashTable.h"
#include "ADS/dictionary/OpenHashTable.h"
#include "ADS/set/SetOperations.h"
#include "ADS/tree/SearchTree.h"
#include <algorithm>
#include <concepts>
#include <cstddef>
#include <functional>
#include <optional>
#include <ranges>
#include <stdexcept>
#include <utility>
#include <vector>
/*--------------------------------------------------------------------------*/
/*--------------------------- NAMESPACE ------------------------------------*/
/*--------------------------------------------------------------------------*/
namespace ADS {
/*--------------------------------------------------------------------------*/
/*-------------------------- CLASS DictionarySet ---------------------------*/
/*--------------------------------------------------------------------------*/
template< class D >
class DictionarySet {
/*--------------------------------------------------------------------------*/
public:
using Item = typename D::Key;
template< class... A >
requires std::constructible_from< D , A... >
explicit DictionarySet( A &&... a );
[[nodiscard]] std::size_t size( void ) const;
[[nodiscard]] bool empty( void ) const;
[[nodiscard]] bool contains( const Item & x ) const;
void insert( const Item & x );
void remove( const Item & x );
template< class F >
void forEach( F && f ) const;
[[nodiscard]] const D & dictionary( void ) const;
/*------------------------- THE STANDARD INTERFACE -------------------------*/
// a constant view of the items, the keys of the dictionary in its order,
// when the dictionary has iterators
[[nodiscard]] auto begin( void ) const
requires std::ranges::forward_range< const D > {
return( KeyIterator( std::ranges::begin( f_d ) ) );
}
[[nodiscard]] auto end( void ) const
requires std::ranges::forward_range< const D > {
return( KeyIterator( std::ranges::end( f_d ) ) );
}
/*--------------------------------------------------------------------------*/
private:
D f_d;
}; // end( class DictionarySet )
template< class T , class H = std::hash< T > >
using ChainedHashSet = DictionarySet< ChainedHashTable< T , bool ,
Chain::FRONT , H > >;
template< class T , class H = std::hash< T > >
using OpenHashSet = DictionarySet< OpenHashTable< T , bool , H > >;
template< std::totally_ordered T >
using TreeSet = DictionarySet< RedBlackTree< T , bool > >;
} // end( namespace ADS )
/*--------------------------------------------------------------------------*/
/*-------------------------- IMPLEMENTATION --------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/set/impl/DictionarySet.tpp"
/*--------------------------------------------------------------------------*/
#endif /* DictionarySet.h included */
/*--------------------------------------------------------------------------*/
/*------------------------ End File DictionarySet.h ------------------------*/
/*--------------------------------------------------------------------------*/