|
| | BucketCuckooTable (std::size_t n=0, H h=H(), Eq eq=Eq(), const A &alloc=A()) |
| | the empty table, with room for \( n \) pairs before it grows, its places from alloc
|
| std::optional< V > | lookup (const K &k) const |
| | the value of the key \( k \), or nothing, from the 8 places of its two buckets, compared first by their tags
|
| const V * | find (const K &k) const |
| | the value of the key \( k \), nil if it is not there
|
| V * | find (const K &k) |
| | the value of the key \( k \), to change in place, nil if it is not there
|
| bool | insert (const K &k, const V &v) |
| | associates the value \( v \) to the key \( k \); true if \( k \) was not there
|
| bool | remove (const K &k) |
| | removes the key \( k \), if it is there, clearing the tag of its place; true if it was
|
| bool | contains (const K &k) const |
| | true if the key \( k \) is there
|
| std::size_t | size (void) const |
| | the number of keys
|
| bool | empty (void) const |
| | true if there are no keys
|
| std::size_t | capacity (void) const |
| | the places, 4 per bucket
|
| double | load (void) const |
| | the load, size() / capacity()
|
| std::size_t | rehashes (void) const |
| | the doublings of the table
|
| std::size_t | moves (void) const |
| | the keys moved by the insertions
|
| std::size_t | stashed (void) const |
| | the keys in the stash, 0 but for degenerate hashes
|
| allocator_type | get_allocator (void) const |
| | the allocator of the places
|
| const_iterator | begin (void) const |
| | the iterator on the first item
|
| const_iterator | end (void) const |
| | the iterator past the last item
|
| const_iterator | cbegin (void) const |
| | the constant iterator on the first item
|
| const_iterator | cend (void) const |
| | the constant iterator past the last item
|
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
class ADS::BucketCuckooTable< K, V, H, Eq, A >
a DICTIONARY on the cuckoo hashing with buckets of 4 places
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
the type of the items, for the standard library
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
| ADS::BucketCuckooTable< K, V, H, Eq, A >::BucketCuckooTable |
( |
std::size_t | n = 0, |
|
|
H | h = H(), |
|
|
Eq | eq = Eq(), |
|
|
const A & | alloc = A() ) |
|
explicit |
the empty table, with room for \( n \) pairs before it grows, its places from alloc
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
the value of the key \( k \), to change in place, nil if it is not there
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
the value of the key \( k \), nil if it is not there
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
associates the value \( v \) to the key \( k \); true if \( k \) was not there
In pseudocode (Li, Andersen, Kaminsky and Freedman, with the stash of Kirsch, Mitzenmacher and Wieder, beyond the book), \( b_1 \) and \( b_2 \) the two buckets of \( k \), \( n \) the keys and \( P \) the places; the search in breadth goes from a bucket to the other buckets of its keys, at most 5 moves deep and 1024 buckets in all:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{insert}( k , v ) \cr
2 & \quad \textbf{if}\ k \text{ is in } b_1 \text{, in } b_2
\text{ or in the stash}\ \textbf{then}\ \text{give it the value } v;
\ \textbf{return false} \cr
3 & \quad \textbf{for}\ g \gets 0 , 1 , 2\ \textbf{do} \cr
4 & \qquad \textbf{if}\ b_1 \text{ or } b_2 \text{ has a free place }
\ \textbf{then}\ \text{put } ( k , v ) \text{ there};\ \textbf{return
true} \cr
5 & \qquad \pi \gets \text{a path in breadth from } \{ b_1 , b_2 \}
\text{ to a bucket with a free place} \cr
6 & \qquad \textbf{if}\ \pi \ne \textbf{nil}\ \textbf{then}\ \text{move }
\text{the keys along } \pi \text{ from its end, put } ( k , v )
\text{ at its start};\ \textbf{return true} \cr
7 & \qquad \textbf{if}\ g = 2\ \textbf{or}\ 2 ( n + 1 ) \le P
\ \textbf{then}\ \textbf{break} \cr
8 & \qquad \text{double the table and place every pair again, those }
\text{that find no place in the stash} \cr
9 & \quad \text{put } ( k , v ) \text{ in the stash};\ \textbf{return
true}
\end{array}}
\]
- Postcondition
- \( k \) is in the table
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
the value of the key \( k \), or nothing, from the 8 places of its two buckets, compared first by their tags
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
removes the key \( k \), if it is there, clearing the tag of its place; true if it was
- Postcondition
- \( k \) is not in the table
template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
the keys in the stash, 0 but for degenerate hashes