|
ADS
Algorithms and Data Structures
|
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 | |
a USet on a vector in no order, the items equal by Eq
| using ADS::ArrayUSet< T, Eq >::Item = T |
the type of the items
|
inlineexplicit |
the empty set
|
nodiscard |
the item equal to \( x \), nil if none, \( O( n ) \)
| bool ADS::ArrayUSet< T, Eq >::insert | ( | const T & | x | ) |
\( x \) added if no item equal to it is there, \( O( n ) \); true if added
|
inlinenodiscard |
the items, in no order
| 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}} \]
|
inlinenodiscard |
the number \( n \) of items