an SSet on a sorted vector, ordered by C
More...
#include <ADS/set/SetInterfaces.h>
|
| using | Item = T |
| | the type of the items
|
|
| | 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
|
template<class T, class C = std::less<>>
class ADS::ArraySSet< T, C >
an SSet on a sorted vector, ordered by C
◆ Item
template<class T, class C = std::less<>>
◆ ArraySSet()
template<class T, class C = std::less<>>
◆ find()
template<class T, class C = std::less<>>
the item equal to \( x \), nil if none, \( O( \log n ) \)
◆ insert()
template<class T, class C = std::less<>>
\( 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<>>
◆ lowerBound()
template<class T, class C = std::less<>>
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<>>
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<>>
the number \( n \) of items
The documentation for this class was generated from the following file: