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

an SSet on a sorted vector, ordered by C More...

#include <ADS/set/SetInterfaces.h>

Public types

using Item = T
 the type of the items

Public member functions

 ArraySSet (C less=C())
 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( \log n ) \)
const T * lowerBound (const T &x) const
 the least item not smaller than \( x \), nil if none, by binary search in \( O( \log n ) \) (Morin's find( x ) of an SSet)
bool insert (const T &x)
 \( x \) added in its place if no item equal to it is there, the items after it moved by one place, \( O( n ) \); true if added
bool remove (const T &x)
 the item equal to \( x \) removed, \( O( n ) \); true if there was one
const std::vector< T > & items (void) const
 the items, increasing

Detailed description

template<class T, class C = std::less<>>
class ADS::ArraySSet< T, C >

an SSet on a sorted vector, ordered by C

Member typedef documentation

◆ Item

template<class T, class C = std::less<>>
using ADS::ArraySSet< T, C >::Item = T

the type of the items

Constructor and destructor documentation

◆ ArraySSet()

template<class T, class C = std::less<>>
ADS::ArraySSet< T, C >::ArraySSet ( C less = C())
inlineexplicit

the empty set

Member function documentation

◆ find()

template<class T, class C = std::less<>>
const T * ADS::ArraySSet< T, C >::find ( const T & x) const
nodiscard

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

◆ insert()

template<class T, class C = std::less<>>
bool ADS::ArraySSet< T, C >::insert ( const T & x)

\( x \) added in its place if no item equal to it is there, the items after it moved by one place, \( O( n ) \); true if added

In pseudocode (Morin, exercises 1.6 and 1.7), \( A[ 0 .. n - 1 ] \) the vector, increasing:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{insert}( x ) \cr 2 & \quad i \gets \min \{ j : j = n\ \textbf{or}\ A[ j ] \ge x \}, \ \text{by binary search} \cr 3 & \quad \textbf{if}\ i < n\ \textbf{and}\ A[ i ] = x\ \textbf{then return false} \cr 4 & \quad A[ i + 1 .. n ] \gets A[ i .. n - 1 ]\quad \triangleright \ \text{one block move} \cr 5 & \quad A[ i ] \gets x;\ n \gets n + 1;\ \textbf{return true} \end{array}} \]

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

◆ items()

template<class T, class C = std::less<>>
const std::vector< T > & ADS::ArraySSet< T, C >::items ( void ) const
inlinenodiscard

the items, increasing

◆ lowerBound()

template<class T, class C = std::less<>>
const T * ADS::ArraySSet< T, C >::lowerBound ( const T & x) const
nodiscard

the least item not smaller than \( x \), nil if none, by binary search in \( O( \log n ) \) (Morin's find( x ) of an SSet)

◆ remove()

template<class T, class C = std::less<>>
bool ADS::ArraySSet< T, C >::remove ( const T & x)

the item equal to \( x \) removed, \( O( n ) \); true if there was one

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

◆ size()

template<class T, class C = std::less<>>
std::size_t ADS::ArraySSet< T, C >::size ( void ) const
inlinenodiscard

the number \( n \) of items


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