|
| | SortedListSet (void)=default |
| | the empty set
|
| | SortedListSet (std::initializer_list< T > items) |
| | the set of the given items, in any order, 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 that stops at the first item not smaller than \( x \), \( O( n ) \) time
|
| void | insert (const T &x) |
| | \( x \) into the set, \( O( n ) \) time, to keep the order
|
| void | insertLast (const T &x) |
| | \( x \), larger than all the items, at the end 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, at the head, none if the set is empty, \( O( 1 ) \) time
|
| std::optional< T > | max (void) const |
| | the largest item, at the tail, none if the set is empty, \( O( 1 ) \) time
|
| template<class F> |
| void | forEach (F &&f) const |
| | f( x ) on the items in increasing order, \( O( n ) \) time
|
| const List< T > & | list (void) const |
| | the sorted list of the items
|
| const_iterator | begin (void) const |
| | the iterator on the smallest item
|
| const_iterator | end (void) const |
| | the iterator past the largest item
|
| const_iterator | cbegin (void) const |
| | as begin()
|
| const_iterator | cend (void) const |
| | as end()
|
template<std::totally_ordered T>
class ADS::SortedListSet< T >
a set as a list sorted in increasing order
template<std::totally_ordered T>
\( x \) into the set, \( O( n ) \) time, to keep the order
In pseudocode (section 8.3), \( L \) the list:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{insert}( x ) \cr
2 & \quad p \gets \text{the first position of } L
\text{ that is finished or holds an item } \ge x \cr
3 & \quad \textbf{if}\ L.\mathrm{finished}( p )\ \textbf{or}\ x <
L.\mathrm{read}( p )\ \textbf{then}\ L.\mathrm{insert}( p , x )\quad
\triangleright\ \text{before } p
\end{array}}
\]
- Postcondition
- \( x \) is in the set
template<std::totally_ordered T>
\( x \) out of the set, \( O( n ) \) time
In pseudocode (section 8.3), the scan of insert():
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{remove}( x ) \cr
2 & \quad p \gets \text{the first position of } L
\text{ that is finished or holds an item } \ge x \cr
3 & \quad \textbf{if}\ \textbf{not}\ L.\mathrm{finished}( p )
\ \textbf{and}\ L.\mathrm{read}( p ) = x\ \textbf{then}
\ L.\mathrm{remove}( p )
\end{array}}
\]
- Postcondition
- \( x \) is not in the set