ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::BucketCuckooTable< K, V, H, Eq, A > Class Template Reference

a DICTIONARY on the cuckoo hashing with buckets of 4 places More...

#include <ADS/dictionary/BucketCuckooTable.h>

Classes

struct  Places
 the places, for SlotIterator More...

Public types

using Key = K
 the type of the keys
using Value = V
 the type of the values
using value_type = std::pair< K , V >
 the type of the items, for the standard library
using key_type = K
 the type of the keys
using mapped_type = V
 the type of the values
using size_type = std::size_t
 the type of the sizes
using difference_type = std::ptrdiff_t
 the type of the distances between two iterators
using reference = PairRef< const K & , const V & >
 a reference to an item
using const_reference = PairRef< const K & , const V & >
 a constant reference to an item
using const_iterator = SlotIterator< BucketCuckooTable , Places >
 the iterator on the items, constant
using iterator = const_iterator
 the iterator on the items
using allocator_type = A
 the type of the allocator

Public member functions

 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

Detailed description

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

Member typedef documentation

◆ allocator_type

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
using ADS::BucketCuckooTable< K, V, H, Eq, A >::allocator_type = A

the type of the allocator

◆ const_iterator

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
using ADS::BucketCuckooTable< K, V, H, Eq, A >::const_iterator = SlotIterator< BucketCuckooTable , Places >

the iterator on the items, constant

◆ const_reference

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
using ADS::BucketCuckooTable< K, V, H, Eq, A >::const_reference = PairRef< const K & , const V & >

a constant reference to an item

◆ difference_type

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
using ADS::BucketCuckooTable< K, V, H, Eq, A >::difference_type = std::ptrdiff_t

the type of the distances between two iterators

◆ iterator

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
using ADS::BucketCuckooTable< K, V, H, Eq, A >::iterator = const_iterator

the iterator on the items

◆ Key

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
using ADS::BucketCuckooTable< K, V, H, Eq, A >::Key = K

the type of the keys

◆ key_type

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
using ADS::BucketCuckooTable< K, V, H, Eq, A >::key_type = K

the type of the keys

◆ mapped_type

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
using ADS::BucketCuckooTable< K, V, H, Eq, A >::mapped_type = V

the type of the values

◆ reference

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
using ADS::BucketCuckooTable< K, V, H, Eq, A >::reference = PairRef< const K & , const V & >

a reference to an item

◆ size_type

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
using ADS::BucketCuckooTable< K, V, H, Eq, A >::size_type = std::size_t

the type of the sizes

◆ Value

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
using ADS::BucketCuckooTable< K, V, H, Eq, A >::Value = V

the type of the values

◆ value_type

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
using ADS::BucketCuckooTable< K, V, H, Eq, A >::value_type = std::pair< K , V >

the type of the items, for the standard library

Constructor and destructor documentation

◆ BucketCuckooTable()

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

Member function documentation

◆ begin()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
const_iterator ADS::BucketCuckooTable< K, V, H, Eq, A >::begin ( void ) const
inlinenodiscard

the iterator on the first item

◆ capacity()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
std::size_t ADS::BucketCuckooTable< K, V, H, Eq, A >::capacity ( void ) const
nodiscard

the places, 4 per bucket

◆ cbegin()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
const_iterator ADS::BucketCuckooTable< K, V, H, Eq, A >::cbegin ( void ) const
inlinenodiscard

the constant iterator on the first item

◆ cend()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
const_iterator ADS::BucketCuckooTable< K, V, H, Eq, A >::cend ( void ) const
inlinenodiscard

the constant iterator past the last item

◆ contains()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
bool ADS::BucketCuckooTable< K, V, H, Eq, A >::contains ( const K & k) const
nodiscard

true if the key \( k \) is there

◆ empty()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
bool ADS::BucketCuckooTable< K, V, H, Eq, A >::empty ( void ) const
nodiscard

true if there are no keys

◆ end()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
const_iterator ADS::BucketCuckooTable< K, V, H, Eq, A >::end ( void ) const
inlinenodiscard

the iterator past the last item

◆ find() [1/2]

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
V * ADS::BucketCuckooTable< K, V, H, Eq, A >::find ( const K & k)
nodiscard

the value of the key \( k \), to change in place, nil if it is not there

◆ find() [2/2]

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
const V * ADS::BucketCuckooTable< K, V, H, Eq, A >::find ( const K & k) const
nodiscard

the value of the key \( k \), nil if it is not there

◆ get_allocator()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
allocator_type ADS::BucketCuckooTable< K, V, H, Eq, A >::get_allocator ( void ) const
inlinenodiscard

the allocator of the places

◆ insert()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
bool ADS::BucketCuckooTable< K, V, H, Eq, A >::insert ( const K & k,
const V & 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

◆ load()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
double ADS::BucketCuckooTable< K, V, H, Eq, A >::load ( void ) const
nodiscard

the load, size() / capacity()

◆ lookup()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
std::optional< V > ADS::BucketCuckooTable< K, V, H, Eq, A >::lookup ( const K & k) const
nodiscard

the value of the key \( k \), or nothing, from the 8 places of its two buckets, compared first by their tags

◆ moves()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
std::size_t ADS::BucketCuckooTable< K, V, H, Eq, A >::moves ( void ) const
nodiscard

the keys moved by the insertions

◆ rehashes()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
std::size_t ADS::BucketCuckooTable< K, V, H, Eq, A >::rehashes ( void ) const
nodiscard

the doublings of the table

◆ remove()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
bool ADS::BucketCuckooTable< K, V, H, Eq, A >::remove ( const K & k)

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

◆ size()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
std::size_t ADS::BucketCuckooTable< K, V, H, Eq, A >::size ( void ) const
nodiscard

the number of keys

◆ stashed()

template<class K, class V, class H = DefaultHash< K >, class Eq = std::equal_to< K >, class A = std::allocator< std::pair< const K , V > >>
std::size_t ADS::BucketCuckooTable< K, V, H, Eq, A >::stashed ( void ) const
nodiscard

the keys in the stash, 0 but for degenerate hashes


The documentation for this class was generated from the following file: