Program Listing for File ListSet.h

↰ Return to documentation for file (ADS/set/ListSet.h)

/*--------------------------------------------------------------------------*/
/*----------------------------- File ListSet.h -----------------------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*----------------------------- DEFINITIONS --------------------------------*/
/*--------------------------------------------------------------------------*/

#ifndef __ADS_ListSet
 #define __ADS_ListSet
                      /* self-identification: #endif constant */

/*--------------------------------------------------------------------------*/
/*------------------------------ INCLUDES ----------------------------------*/
/*--------------------------------------------------------------------------*/

#include "ADS/Contract.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 ListSet ------------------------------*/
/*--------------------------------------------------------------------------*/

template< std::equality_comparable T >
class ListSet {

/*--------------------------------------------------------------------------*/
 public:

 using Item = T;

 ListSet( void ) = default;

 ListSet( std::initializer_list< T > items );

 [[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 insertNew( const T & x );

 void remove( const T & x );

 [[nodiscard]] std::optional< T > min( void ) const
  requires std::totally_ordered< T >;

 template< class F >
 void forEach( F && f ) const;

/*------------------------- THE STANDARD INTERFACE -------------------------*/

 // a constant view of the items in the order of the list, 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_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:

 typename List< T >::Pos find( const T & x ) const;

 [[nodiscard]] bool distinct( void ) const;

 List< T > f_L;
 std::size_t f_size = 0;

 };  // end( class ListSet )

template< class T >
ListSet< T > setUnion( const ListSet< T > & A , const ListSet< T > & B );

template< class T >
ListSet< T > setIntersection( const ListSet< T > & A ,
                              const ListSet< T > & B );

template< class T >
ListSet< T > setDifference( const ListSet< T > & A , const ListSet< T > & B );

template< class T >
ListSet< T > setSymmetricDifference( const ListSet< T > & A ,
                                     const ListSet< T > & B );

}  // end( namespace ADS )

/*--------------------------------------------------------------------------*/
/*-------------------------- IMPLEMENTATION --------------------------------*/
/*--------------------------------------------------------------------------*/

#include "ADS/set/impl/ListSet.tpp"

/*--------------------------------------------------------------------------*/

#endif  /* ListSet.h included */

/*--------------------------------------------------------------------------*/
/*--------------------------- End File ListSet.h ---------------------------*/
/*--------------------------------------------------------------------------*/