a set on a hash table whose foreach follows the order of insertion: a LIST keeps the items in that order and the table maps each item to its position, so insert(), remove() and contains() take \( O( 1 ) \) expected time and forEach() \( O( n ) \) (exercise 8.9)
More...
#include <ADS/set/LinkedHashSet.h>
|
| | LinkedHashSet (void) |
| | the empty set
|
| | LinkedHashSet (const LinkedHashSet &o) |
| | a copy, with positions into its own list
|
| LinkedHashSet & | operator= (const LinkedHashSet &)=delete |
| | no assignment, which would copy the positions into the list of another set
|
| 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 search in the table
|
| void | insert (const T &x) |
| | \( x \) into the set: a new item goes to the end of the order, and an item already there keeps its place
|
| void | remove (const T &x) |
| | \( x \) out of the set, and out of the order
|
| template<class F> |
| void | forEach (F &&f) const |
| | f( x ) on the items in the order of insertion, \( O( n ) \) time
|
| const_iterator | begin (void) const |
| | the iterator on the first item inserted
|
| const_iterator | end (void) const |
| | the iterator past the last item inserted
|
| const_iterator | cbegin (void) const |
| | as begin()
|
| const_iterator | cend (void) const |
| | as end()
|
template<class T, class H = std::hash< T >>
class ADS::LinkedHashSet< T, H >
a set on a hash table whose foreach follows the order of insertion: a LIST keeps the items in that order and the table maps each item to its position, so insert(), remove() and contains() take \( O( 1 ) \) expected time and forEach() \( O( n ) \) (exercise 8.9)
◆ const_iterator
template<class T, class H = std::hash< T >>
the iterator of the list of the order, constant
◆ const_reference
template<class T, class H = std::hash< T >>
◆ difference_type
template<class T, class H = std::hash< T >>
◆ Item
template<class T, class H = std::hash< T >>
◆ iterator
template<class T, class H = std::hash< T >>
◆ reference
template<class T, class H = std::hash< T >>
◆ size_type
template<class T, class H = std::hash< T >>
◆ value_type
template<class T, class H = std::hash< T >>
◆ LinkedHashSet() [1/2]
template<class T, class H = std::hash< T >>
◆ LinkedHashSet() [2/2]
template<class T, class H = std::hash< T >>
a copy, with positions into its own list
◆ begin()
template<class T, class H = std::hash< T >>
the iterator on the first item inserted
◆ cbegin()
template<class T, class H = std::hash< T >>
◆ cend()
template<class T, class H = std::hash< T >>
◆ contains()
template<class T, class H = std::hash< T >>
whether \( x \) is in the set, by a search in the table
◆ empty()
template<class T, class H = std::hash< T >>
whether the set has no item
◆ end()
template<class T, class H = std::hash< T >>
the iterator past the last item inserted
◆ forEach()
template<class T, class H = std::hash< T >>
template<class F>
f( x ) on the items in the order of insertion, \( O( n ) \) time
◆ insert()
template<class T, class H = std::hash< T >>
\( x \) into the set: a new item goes to the end of the order, and an item already there keeps its place
In pseudocode (exercise 8.9), \( L \) the list of the order and \( D \) the table of the positions:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{insert}( x )\quad \triangleright\ D
\text{ maps an item to its cell in } L \cr
2 & \quad \textbf{if}\ D.\mathrm{lookup}( x ) \ne \textbf{nil}
\ \textbf{then return} \cr
3 & \quad p \gets L.\mathrm{insert}( L.\mathrm{next}( L.\mathrm{tail}()
) , x )\quad \triangleright\ \text{last, in the order of insertion}
\cr
4 & \quad D.\mathrm{insert}( x , p )
\end{array}}
\]
- Postcondition
- \( x \) is in the set
◆ operator=()
template<class T, class H = std::hash< T >>
no assignment, which would copy the positions into the list of another set
◆ remove()
template<class T, class H = std::hash< T >>
\( x \) out of the set, and out of the order
In pseudocode (exercise 8.9):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{procedure}\ \mathrm{remove}( x ) \cr
2 & \quad p \gets D.\mathrm{lookup}( x );\ \textbf{if}\ p =
\textbf{nil}\ \textbf{then return} \cr
3 & \quad D.\mathrm{remove}( x );\ L.\mathrm{remove}( p )\quad
\triangleright\ O( 1 ) \text{, the cell is known}
\end{array}}
\]
- Postcondition
- \( x \) is not in the set
◆ size()
template<class T, class H = std::hash< T >>
The documentation for this class was generated from the following file: