125#ifndef __ADS_OpenHashTable
126 #define __ADS_OpenHashTable
177 using Step = std::function< std::size_t( std::size_t ) >;
209 [[nodiscard]] std::size_t
at( std::size_t h , std::size_t i ,
210 std::size_t m )
const;
215 [[nodiscard]]
static std::size_t
step( std::size_t h , std::size_t m );
221 [[nodiscard]] std::size_t
stride( std::size_t h , std::size_t m )
const;
224 [[nodiscard]]
bool works( std::size_t m )
const;
234 Probing(
Kind k ,
long c1 ,
long c2 );
237 static std::size_t mod(
long c , std::size_t m );
241 const std::vector< std::size_t > & permutation( std::size_t m )
const;
247 unsigned long f_seed = 0;
248 mutable std::vector< std::size_t > f_p;
249 mutable std::size_t f_m = 0;
258template<
class K ,
class V ,
class H = std::hash< K > >
309 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
332 void insert(
const K & k ,
const V & v );
347 [[nodiscard]]
const K *
findKey(
const K & k )
const;
350 [[nodiscard]] std::size_t
size(
void )
const;
353 [[nodiscard]]
bool empty(
void )
const;
359 [[nodiscard]]
double load(
void )
const;
372 [[nodiscard]]
const K &
keyAt( std::size_t i )
const;
375 [[nodiscard]] std::size_t
probes(
void )
const;
381 [[nodiscard]] std::size_t
moved(
void )
const;
393 static std::size_t
size(
const auto & o ) {
return( o.f_T.size() ); }
395 static bool occupied(
const auto & o , std::size_t i ) {
399 static auto read(
const auto & o , std::size_t i ) {
447 [[nodiscard]]
bool is( std::size_t i ,
const K & k )
const;
453 std::size_t scan(
const K & k ,
bool insert )
const;
456 [[nodiscard]] std::size_t hashOf(
const K & k )
const;
460 [[nodiscard]] std::size_t where(
const K & k )
const;
466 [[nodiscard]]
bool consistent(
const K & k )
const;
469 void rebuild( std::size_t m );
471 std::vector< Cell > f_T;
474 std::size_t f_linear = 0;
477 std::size_t f_size = 0;
478 std::size_t f_deleted = 0;
483 std::atomic< std::size_t > n{ 0 };
485 Probes(
void ) =
default;
487 Probes(
const Probes & o ) : n( o.n.
load( std::memory_order_relaxed ) ) { }
489 Probes & operator=(
const Probes & o ) {
490 n.store( o.n.load( std::memory_order_relaxed ) ,
491 std::memory_order_relaxed );
495 mutable Probes f_probes;
496 std::size_t f_rebuilds = 0;
497 std::size_t f_moved = 0;
509#include "ADS/dictionary/impl/OpenHashTable.tpp"
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...
Random numbers as Knuth treats them (chapter 3 of The Art of Computer Programming),...
The sizes of the hash tables that restructure themselves (section 7.4): a size that is a power of two...
SlotIterator< OpenHashTable, Places > const_iterator
the iterator on the items, constant
Definition OpenHashTable.h:420
PairRef< const K &, const V & > const_reference
a constant reference to an item
Definition OpenHashTable.h:418
void remove(const K &k)
removes the key , if it is there, leaving a deleted place, by scan( k , false ) of lookup(); the tabl...
bool contains(const K &k) const
true if the key is there
Slot
the state of a place
Definition OpenHashTable.h:268
@ DELETED
emptied by remove(): an inspection goes past it
Definition OpenHashTable.h:271
@ FULL
it holds a pair
Definition OpenHashTable.h:270
@ NIL
never used: it stops an inspection
Definition OpenHashTable.h:269
std::size_t moved(void) const
the number of pairs moved by the restructurings so far
std::size_t restructures(void) const
the number of restructurings so far
std::optional< V > lookup(const K &k) const
the value of the key , or nothing
const_iterator cend(void) const
the constant iterator past the last item
Definition OpenHashTable.h:435
const_iterator begin(void) const
the iterator on the first item
Definition OpenHashTable.h:425
bool empty(void) const
true if there are no keys
void insert(const K &k, const V &v)
associates the value to the key ; throws std::overflow_error if the inspection finds no place
Slot slot(std::size_t i) const
the state of the place
const_iterator end(void) const
the iterator past the last item
Definition OpenHashTable.h:429
V Value
the type of the values
Definition OpenHashTable.h:265
void forEach(F &&f) const
the foreach of the book: f( k , v ) on the pairs, place after place, time
const_iterator iterator
the iterator on the items
Definition OpenHashTable.h:422
std::size_t capacity(void) const
the size of the vector
PairRef< const K &, const V & > reference
a reference to an item
Definition OpenHashTable.h:416
const K & keyAt(std::size_t i) const
the key in the place
K Key
the type of the keys
Definition OpenHashTable.h:264
OpenHashTable(std::size_t m, Probing probe, bool restructure=false, H h=H())
the empty table of size m with the given inspection, which restructures itself or not
const_iterator cbegin(void) const
the constant iterator on the first item
Definition OpenHashTable.h:433
std::ptrdiff_t difference_type
the type of the distances between two iterators
Definition OpenHashTable.h:414
double load(void) const
the load factor
const K * findKey(const K &k) const
the address of the key , nil if absent, in expected time: the find( x ) of a USet of Morin,...
V mapped_type
the type of the values
Definition OpenHashTable.h:410
std::size_t size_type
the type of the sizes
Definition OpenHashTable.h:412
std::size_t probes(void) const
the places examined by the last operation
K key_type
the type of the keys
Definition OpenHashTable.h:408
std::size_t size(void) const
the number of keys
std::pair< K, V > value_type
the type of the items, for the standard library
Definition OpenHashTable.h:406
a sequence of inspection of an OpenHashTable
Definition OpenHashTable.h:163
static Probing pseudo_random(unsigned long seed=1)
, a random permutation of with , drawn from the seed for each
static Probing double_hashing(void)
Kind
the kind of the inspection
Definition OpenHashTable.h:168
@ RANDOM
Definition OpenHashTable.h:173
@ TRIANGULAR
Definition OpenHashTable.h:172
@ QUADRATIC
Definition OpenHashTable.h:170
@ LINEAR
Definition OpenHashTable.h:169
@ DOUBLE
Definition OpenHashTable.h:171
static Probing double_hashing(Step g)
, the step from
Kind kind(void) const
the kind of the inspection
static Probing quadratic(long c1, long c2)
, prime
static std::size_t step(std::size_t h, std::size_t m)
the step of the double hashing, coprime with when is prime or a power of two
void check(std::size_t m) const
checks that the sequence works with
static Probing linear(long delta=1)
bool works(std::size_t m) const
whether the sequence can work with a table of size
std::function< std::size_t(std::size_t) > Step
the second function of the double hashing, of the hash
Definition OpenHashTable.h:177
static Probing triangular(void)
, a power of two
std::size_t stride(std::size_t h, std::size_t m) const
the constant difference of the linear inspection and of the double hashing, so that a scan adds it i...
std::size_t at(std::size_t h, std::size_t i, std::size_t m) const
the place in a table of size , from
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
constexpr int NIL
no node
Definition Visit.h:128
the places of the table, for SlotIterator
Definition OpenHashTable.h:391
static bool occupied(const auto &o, std::size_t i)
whether the place is full
Definition OpenHashTable.h:395
static auto read(const auto &o, std::size_t i)
the pair of the place
Definition OpenHashTable.h:399
static std::size_t size(const auto &o)
the number of places
Definition OpenHashTable.h:393