94#ifndef __ADS_CuckooHashing
95 #define __ADS_CuckooHashing
129template<
class K ,
class V ,
class H = std::hash< K > ,
130 class A = std::allocator< std::pair< const K , V > > >
143 std::size_t s = 0 , std::uint64_t seed = 1 ,
144 H h = H() ,
const A & alloc = A() );
149 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
190 void insert(
const K & k ,
const V & v );
201 [[nodiscard]] std::size_t
size(
void )
const;
213 [[nodiscard]] std::size_t
stashed(
void )
const;
235 static std::size_t
size(
const auto & o ) {
return( o.f_T.size() ); }
237 static bool occupied(
const auto & o , std::size_t i ) {
238 return( o.f_T[ i ].full );
241 static auto read(
const auto & o , std::size_t i ) {
287 [[nodiscard]] std::size_t place(
const K & k ,
int i )
const;
290 [[nodiscard]] std::optional< std::size_t > find(
const K & k )
const;
294 bool walk( Cell & c );
297 bool settle( Cell & c );
301 void rebuild( std::size_t m , std::optional< Cell > extra );
308 [[nodiscard]]
bool placed(
const K & k )
const;
310 static constexpr int kReseeds = 8;
311 detail::AllocVector< A , Cell > f_T;
317 std::size_t f_rehashes = 0;
318 std::size_t f_evictions = 0;
333#include "ADS/dictionary/impl/CuckooHashing.tpp"
The rules of the allocator-aware containers of the standard ([container.reqmts], [allocator....
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The iterators that the containers of the library have in common, beyond the book: they give a contain...
Hashing with random tables, beyond the book:
std::size_t size(void) const
the number of keys
K Key
the type of the keys
Definition CuckooHashing.h:136
std::ptrdiff_t difference_type
the type of the distances between two iterators
Definition CuckooHashing.h:256
allocator_type get_allocator(void) const
the allocator of the places
Definition CuckooHashing.h:268
CuckooHashTable(std::size_t m=16, double maxLoad=0.4, std::size_t s=0, std::uint64_t seed=1, H h=H(), const A &alloc=A())
the empty table of places and a stash of places, from alloc
A allocator_type
the type of the allocator
Definition CuckooHashing.h:266
V Value
the type of the values
Definition CuckooHashing.h:137
std::size_t size_type
the type of the sizes
Definition CuckooHashing.h:254
K key_type
the type of the keys
Definition CuckooHashing.h:250
bool contains(const K &k) const
true if the key is there
V mapped_type
the type of the values
Definition CuckooHashing.h:252
const_iterator iterator
the iterator on the items
Definition CuckooHashing.h:264
std::size_t stashed(void) const
the keys in the stash
PairRef< const K &, const V & > reference
a reference to an item
Definition CuckooHashing.h:258
PairRef< const K &, const V & > const_reference
a constant reference to an item
Definition CuckooHashing.h:260
void insert(const K &k, const V &v)
associates the value to the key , in amortized expected time
const_iterator cbegin(void) const
the constant iterator on the first item
Definition CuckooHashing.h:281
std::optional< V > lookup(const K &k) const
the value of the key , or nothing, from its two places and and the stash, in the worst case
const_iterator cend(void) const
the constant iterator past the last item
Definition CuckooHashing.h:283
std::size_t capacity(void) const
the number of places, the stash excluded
SlotIterator< CuckooHashTable, Places > const_iterator
the iterator on the items, constant
Definition CuckooHashing.h:262
const_iterator begin(void) const
the iterator on the first item
Definition CuckooHashing.h:273
std::size_t rehashes(void) const
the rebuilds with new functions after a failed insertion
std::size_t evictions(void) const
the evictions made by the insertions
std::pair< K, V > value_type
the type of the items, for the standard library
Definition CuckooHashing.h:248
void remove(const K &k)
removes the key , if it is there, emptying its place; the table is halved below a load of
const_iterator end(void) const
the iterator past the last item
Definition CuckooHashing.h:277
a bidirectional iterator on the occupied places of the table O, by the policy P with the static funct...
Definition Iterators.h:691
the generator SplitMix64, a UniformRandomBitGenerator
Definition RandomHashing.h:122
the simple tabulation hashing of the keys of 64 bits
Definition RandomHashing.h:220
std::conditional_t< detail::plainPair< A, B, VA, VB >, std::pair< A, B >, detail::PairProxy< A, B, VA, VB > > PairRef
the pair that an iterator reads by value, in general two references into the container,...
Definition Iterators.h:648
the places and the stash, for SlotIterator
Definition CuckooHashing.h:233
static bool occupied(const auto &o, std::size_t i)
whether the place holds a key
Definition CuckooHashing.h:237
static auto read(const auto &o, std::size_t i)
the pair of the place
Definition CuckooHashing.h:241
static std::size_t size(const auto &o)
the number of places, the stash included
Definition CuckooHashing.h:235