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

a USet on a vector in no order, the items equal by Eq More...

#include <ADS/set/SetInterfaces.h>

Public types

using Item = T
 the type of the items

Public member functions

 ArrayUSet (Eq eq=Eq())
 the empty set
std::size_t size (void) const
 the number \( n \) of items
const T * find (const T &x) const
 the item equal to \( x \), nil if none, \( O( n ) \)
bool insert (const T &x)
 \( x \) added if no item equal to it is there, \( O( n ) \); true if added
bool remove (const T &x)
 the item equal to \( x \) removed, the last one moved into its place, \( O( n ) \); true if there was one
const std::vector< T > & items (void) const
 the items, in no order

Detailed description

template<class T, class Eq = std::equal_to<>>
class ADS::ArrayUSet< T, Eq >

a USet on a vector in no order, the items equal by Eq

Member typedef documentation

◆ Item

template<class T, class Eq = std::equal_to<>>
using ADS::ArrayUSet< T, Eq >::Item = T

the type of the items

Constructor and destructor documentation

◆ ArrayUSet()

template<class T, class Eq = std::equal_to<>>
ADS::ArrayUSet< T, Eq >::ArrayUSet ( Eq eq = Eq())
inlineexplicit

the empty set

Member function documentation

◆ find()

template<class T, class Eq = std::equal_to<>>
const T * ADS::ArrayUSet< T, Eq >::find ( const T & x) const
nodiscard

the item equal to \( x \), nil if none, \( O( n ) \)

◆ insert()

template<class T, class Eq = std::equal_to<>>
bool ADS::ArrayUSet< T, Eq >::insert ( const T & x)

\( x \) added if no item equal to it is there, \( O( n ) \); true if added

Postcondition
an item equal to \( x \) is there

◆ items()

template<class T, class Eq = std::equal_to<>>
const std::vector< T > & ADS::ArrayUSet< T, Eq >::items ( void ) const
inlinenodiscard

the items, in no order

◆ remove()

template<class T, class Eq = std::equal_to<>>
bool ADS::ArrayUSet< T, Eq >::remove ( const T & x)

the item equal to \( x \) removed, the last one moved into its place, \( O( n ) \); true if there was one

In pseudocode (Morin, exercise 1.6), \( A[ 0 .. n - 1 ] \) the vector:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{remove}( x ) \cr 2 & \quad i \gets \text{the index of an item equal to } x \text{ in } A,\ \text{by a scan};\ \textbf{if}\ \text{none}\ \textbf{then return false} \cr 3 & \quad A[ i ] \gets A[ n - 1 ];\ n \gets n - 1; \ \textbf{return true} \end{array}} \]

Postcondition
no item equal to \( x \) is there

◆ size()

template<class T, class Eq = std::equal_to<>>
std::size_t ADS::ArrayUSet< T, Eq >::size ( void ) const
inlinenodiscard

the number \( n \) of items


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