104#ifndef __ADS_BucketCuckooTable
105 #define __ADS_BucketCuckooTable
139template<
class K ,
class V ,
class H = DefaultHash< K > ,
140 class Eq = std::equal_to< K > ,
141 class A = std::allocator< std::pair< const K , V > > >
153 const A & alloc = A() );
157 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
160 [[nodiscard]]
const V *
find(
const K & k )
const;
164 [[nodiscard]] V *
find(
const K & k );
198 bool insert(
const K & k ,
const V & v );
209 [[nodiscard]] std::size_t
size(
void )
const;
212 [[nodiscard]]
bool empty(
void )
const;
218 [[nodiscard]]
double load(
void )
const;
224 [[nodiscard]] std::size_t
moves(
void )
const;
227 [[nodiscard]] std::size_t
stashed(
void )
const;
237 static constexpr int kDepth = 5;
238 static constexpr std::size_t kNodes = 1024;
239 static constexpr int kGrowths = 2;
251 static std::size_t
size(
const auto & o ) {
252 return( o.f_S.size() + o.f_X.size() );
256 static bool occupied(
const auto & o , std::size_t i ) {
257 if( i >= o.f_S.size() )
258 return( o.f_XT[ i - o.f_S.size() ] != 0 );
259 return( ( o.f_T[ i >> 2 ] >> ( 8 * ( i & 3 ) ) ) & 0xFF );
262 static auto read(
const auto & o , std::size_t i ) {
263 const Slot & s = o.at( i );
309 [[nodiscard]] std::uint64_t hash(
const K & k )
const;
312 [[nodiscard]]
static std::uint32_t tag( std::uint64_t h );
315 [[nodiscard]] std::size_t first( std::uint64_t h )
const;
319 [[nodiscard]] std::size_t other( std::size_t b , std::uint32_t t )
const;
323 [[nodiscard]] std::size_t locate(
const K & k , std::uint64_t h )
const;
326 [[nodiscard]]
const Slot & at( std::size_t i )
const;
329 [[nodiscard]] Slot & at( std::size_t i );
332 template<
class KK ,
class VV >
333 void stash( KK && k , VV && v );
336 [[nodiscard]]
int freePlace( std::size_t b )
const;
340 template<
class KK ,
class VV >
341 void put( std::size_t b ,
int i , std::uint32_t t , KK && k , VV && v );
345 std::size_t makeRoom( std::uint64_t h );
351 template<
class KK ,
class VV >
352 bool place( std::uint64_t h , KK && k , VV && v );
356 [[nodiscard]]
bool placed(
const K & k )
const;
359 using Tags = detail::AllocVector< A , std::uint32_t >;
361 using Slots = detail::AllocVector< A , Slot >;
367 std::size_t f_xn = 0;
370 std::size_t f_rehashes = 0;
371 std::size_t f_moves = 0;
385#include "ADS/dictionary/impl/BucketCuckooTable.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 engineered hash functions of ADS, beyond the book [see HashFunctions.h for those of section 7....
The iterators that the containers of the library have in common, beyond the book: they give a contain...
The prefetch of a line of the cache, beyond the book: ADS::prefetch( p ) asks the processor to bring ...
std::optional< V > lookup(const K &k) const
the value of the key , or nothing, from the 8 places of its two buckets, compared first by their tags
allocator_type get_allocator(void) const
the allocator of the places
Definition BucketCuckooTable.h:289
PairRef< const K &, const V & > const_reference
a constant reference to an item
Definition BucketCuckooTable.h:281
PairRef< const K &, const V & > reference
a reference to an item
Definition BucketCuckooTable.h:279
std::size_t size_type
the type of the sizes
Definition BucketCuckooTable.h:275
std::size_t size(void) const
the number of keys
std::ptrdiff_t difference_type
the type of the distances between two iterators
Definition BucketCuckooTable.h:277
const_iterator end(void) const
the iterator past the last item
Definition BucketCuckooTable.h:298
bool insert(const K &k, const V &v)
associates the value to the key ; true if was not there
std::size_t rehashes(void) const
the doublings of the table
const_iterator cbegin(void) const
the constant iterator on the first item
Definition BucketCuckooTable.h:302
std::size_t capacity(void) const
the places, 4 per bucket
BucketCuckooTable(std::size_t n=0, H h=H(), Eq eq=Eq(), const A &alloc=A())
the empty table, with room for pairs before it grows, its places from alloc
SlotIterator< BucketCuckooTable, Places > const_iterator
the iterator on the items, constant
Definition BucketCuckooTable.h:283
double load(void) const
the load, size() / capacity()
V mapped_type
the type of the values
Definition BucketCuckooTable.h:273
K Key
the type of the keys
Definition BucketCuckooTable.h:147
const V * find(const K &k) const
the value of the key , nil if it is not there
K key_type
the type of the keys
Definition BucketCuckooTable.h:271
std::size_t stashed(void) const
the keys in the stash, 0 but for degenerate hashes
const_iterator begin(void) const
the iterator on the first item
Definition BucketCuckooTable.h:294
bool remove(const K &k)
removes the key , if it is there, clearing the tag of its place; true if it was
V Value
the type of the values
Definition BucketCuckooTable.h:148
A allocator_type
the type of the allocator
Definition BucketCuckooTable.h:287
const_iterator iterator
the iterator on the items
Definition BucketCuckooTable.h:285
V * find(const K &k)
the value of the key , to change in place, nil if it is not there
const_iterator cend(void) const
the constant iterator past the last item
Definition BucketCuckooTable.h:304
std::pair< K, V > value_type
the type of the items, for the standard library
Definition BucketCuckooTable.h:269
bool empty(void) const
true if there are no keys
std::size_t moves(void) const
the keys moved by the insertions
bool contains(const K &k) const
true if the key is there
a bidirectional iterator on the occupied places of the table O, by the policy P with the static funct...
Definition Iterators.h:691
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, for SlotIterator
Definition BucketCuckooTable.h:249
static auto read(const auto &o, std::size_t i)
the pair of the place
Definition BucketCuckooTable.h:262
static bool occupied(const auto &o, std::size_t i)
whether the place holds a key, i.e., its tag is not 0, or its place of the stash is not a hole
Definition BucketCuckooTable.h:256
static std::size_t size(const auto &o)
the number of places, the stash included
Definition BucketCuckooTable.h:251