ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::ListSet< T > Class Template Reference

a set as an unsorted list More...

#include <ADS/set/ListSet.h>

Public types

using Item = T
 the type of the items
using value_type = T
 the items
using size_type = std::size_t
 the sizes
using difference_type = std::ptrdiff_t
 the distances
using reference = const T &
 a constant reference
using const_reference = const T &
 a constant reference
using const_iterator = typename List< T >::const_iterator
 the iterator of the list, constant
using iterator = const_iterator
 the same, constant

Public member functions

 ListSet (void)=default
 the empty set
 ListSet (std::initializer_list< T > items)
 the set of the given items, a repeated one taken once
std::size_t size (void) const
 the number of items
bool empty (void) const
 whether the set has no item
bool contains (const T &x) const
 whether \( x \) is in the set, by a scan of the list, \( O( n ) \) time
void insert (const T &x)
 \( x \) into the set, \( O( n ) \) time, for the check that \( x \) is not there
void insertNew (const T &x)
 \( x \), which must not be there, at the head of the list, \( O( 1 ) \) time
void remove (const T &x)
 \( x \) out of the set, \( O( n ) \) time
std::optional< T > min (void) const
 the smallest item, none if the set is empty, by a scan, \( O( n ) \) time
template<class F>
void forEach (F &&f) const
 f( x ) on the items, from the last inserted, \( O( n ) \) time
const_iterator begin (void) const
 the iterator on the item at the head of the list
const_iterator end (void) const
 the iterator past the last item
const_iterator cbegin (void) const
 as begin()
const_iterator cend (void) const
 as end()

Detailed description

template<std::equality_comparable T>
class ADS::ListSet< T >

a set as an unsorted list

Member typedef documentation

◆ const_iterator

template<std::equality_comparable T>
using ADS::ListSet< T >::const_iterator = typename List< T >::const_iterator

the iterator of the list, constant

◆ const_reference

template<std::equality_comparable T>
using ADS::ListSet< T >::const_reference = const T &

a constant reference

◆ difference_type

template<std::equality_comparable T>
using ADS::ListSet< T >::difference_type = std::ptrdiff_t

the distances

◆ Item

template<std::equality_comparable T>
using ADS::ListSet< T >::Item = T

the type of the items

◆ iterator

template<std::equality_comparable T>
using ADS::ListSet< T >::iterator = const_iterator

the same, constant

◆ reference

template<std::equality_comparable T>
using ADS::ListSet< T >::reference = const T &

a constant reference

◆ size_type

template<std::equality_comparable T>
using ADS::ListSet< T >::size_type = std::size_t

the sizes

◆ value_type

template<std::equality_comparable T>
using ADS::ListSet< T >::value_type = T

the items

Constructor and destructor documentation

◆ ListSet() [1/2]

template<std::equality_comparable T>
ADS::ListSet< T >::ListSet ( void )
default

the empty set

◆ ListSet() [2/2]

template<std::equality_comparable T>
ADS::ListSet< T >::ListSet ( std::initializer_list< T > items)

the set of the given items, a repeated one taken once

Member function documentation

◆ begin()

template<std::equality_comparable T>
const_iterator ADS::ListSet< T >::begin ( void ) const
inlinenodiscard

the iterator on the item at the head of the list

◆ cbegin()

template<std::equality_comparable T>
const_iterator ADS::ListSet< T >::cbegin ( void ) const
inlinenodiscard

as begin()

◆ cend()

template<std::equality_comparable T>
const_iterator ADS::ListSet< T >::cend ( void ) const
inlinenodiscard

as end()

◆ contains()

template<std::equality_comparable T>
bool ADS::ListSet< T >::contains ( const T & x) const
nodiscard

whether \( x \) is in the set, by a scan of the list, \( O( n ) \) time

◆ empty()

template<std::equality_comparable T>
bool ADS::ListSet< T >::empty ( void ) const
nodiscard

whether the set has no item

◆ end()

template<std::equality_comparable T>
const_iterator ADS::ListSet< T >::end ( void ) const
inlinenodiscard

the iterator past the last item

◆ forEach()

template<std::equality_comparable T>
template<class F>
void ADS::ListSet< T >::forEach ( F && f) const

f( x ) on the items, from the last inserted, \( O( n ) \) time

◆ insert()

template<std::equality_comparable T>
void ADS::ListSet< T >::insert ( const T & x)

\( x \) into the set, \( O( n ) \) time, for the check that \( x \) is not there

In pseudocode (section 8.2):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{insert}( x ) \cr 2 & \quad \textbf{if not}\ \mathrm{contains}( x )\ \textbf{then} \ \mathrm{insertNew}( x ) \end{array}} \]

Postcondition
\( x \) is in the set

◆ insertNew()

template<std::equality_comparable T>
void ADS::ListSet< T >::insertNew ( const T & x)

\( x \), which must not be there, at the head of the list, \( O( 1 ) \) time

Precondition
\( x \) is not in the set (an audit, \( O( n ) \))

◆ min()

template<std::equality_comparable T>
std::optional< T > ADS::ListSet< T >::min ( void ) const
nodiscard

the smallest item, none if the set is empty, by a scan, \( O( n ) \) time

◆ remove()

template<std::equality_comparable T>
void ADS::ListSet< T >::remove ( const T & x)

\( x \) out of the set, \( O( n ) \) time

In pseudocode (section 8.2), \( L \) the list:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{remove}( x ) \cr 2 & \quad \textbf{foreach}\ \text{position } p \text{ of } L \ \textbf{do}\quad \triangleright\ x \text{ appears once at most} \cr 3 & \qquad \textbf{if}\ L.\mathrm{read}( p ) = x\ \textbf{then} \ L.\mathrm{remove}( p );\ \textbf{return} \end{array}} \]

Postcondition
\( x \) is not in the set

◆ size()

template<std::equality_comparable T>
std::size_t ADS::ListSet< T >::size ( void ) const
nodiscard

the number of items


The documentation for this class was generated from the following file: