59#ifndef __ADS_ChainedHashTable
60 #define __ADS_ChainedHashTable
100 class H = std::hash< K > >
146 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
168 void insert(
const K & k ,
const V & v );
183 [[nodiscard]]
const K *
findKey(
const K & k )
const;
186 [[nodiscard]] std::size_t
size(
void )
const;
189 [[nodiscard]]
bool empty(
void )
const;
195 [[nodiscard]]
double load(
void )
const;
204 [[nodiscard]] std::vector< K >
chain( std::size_t i )
const;
208 [[nodiscard]] std::size_t
probes(
void )
const;
214 [[nodiscard]] std::size_t
moved(
void )
const;
218 using Pair = std::pair< K , V >;
233 using Lists = std::vector< Bucket >;
252 if( f_b < f_T->
size() )
253 f_c = ( *f_T )[ f_b ].
begin();
282 ( ( f_T ==
nullptr ) || ( f_b >= f_T->size() ) || ( f_c == o.f_c ) ) );
289 while( ( f_b < f_T->
size() ) && ( f_c == ( *f_T )[ f_b ].
end() ) )
290 if( ++f_b < f_T->
size() )
291 f_c = ( *f_T )[ f_b ].begin();
294 const Lists * f_T =
nullptr;
296 typename Bucket::const_iterator f_c;
328 [[nodiscard]] std::size_t place(
const K & k )
const;
332 Pos find(
const Bucket & L ,
const K & k )
const;
335 [[nodiscard]]
bool present(
const K & k )
const;
340 [[nodiscard]]
bool consistent(
const K & k )
const;
344 [[nodiscard]]
bool listOk( std::size_t i ,
const K & k ,
345 std::size_t & n )
const;
348 void rebuild( std::size_t m );
350 mutable std::vector< Bucket > f_T;
354 double f_shrink = 0.5;
356 std::size_t f_size = 0;
357 mutable std::size_t f_probes = 0;
358 std::size_t f_rebuilds = 0;
359 std::size_t f_moved = 0;
371#include "ADS/dictionary/impl/ChainedHashTable.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The LIST of the book: a SEQUENCE [see ADT.h] realized as a bidirectional circular list of cells with ...
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
The sizes of the hash tables that restructure themselves (section 7.4): a size that is a power of two...
the iterator on the pairs, list by list
Definition ChainedHashTable.h:232
bool operator==(const const_iterator &o) const
equal on the same pair, or both at the end
Definition ChainedHashTable.h:279
pointer operator->(void) const
the address of the pair
Definition ChainedHashTable.h:261
const_iterator & operator++(void)
to the next pair, on the next list that is not empty after the last pair of a list
Definition ChainedHashTable.h:265
std::forward_iterator_tag iterator_category
the category of the iterator
Definition ChainedHashTable.h:237
const_iterator(void)=default
the end of no table
const_iterator operator++(int)
to the next pair, returning the iterator before the step
Definition ChainedHashTable.h:272
const Pair & reference
a reference to an item
Definition ChainedHashTable.h:243
const Pair * pointer
a pointer to an item
Definition ChainedHashTable.h:245
Pair value_type
the type of the items, for the standard library
Definition ChainedHashTable.h:239
reference operator*(void) const
the pair
Definition ChainedHashTable.h:258
const_iterator(const Lists *T, std::size_t b)
on the first pair from the list , or at the end
Definition ChainedHashTable.h:251
std::ptrdiff_t difference_type
the type of the distances between two iterators
Definition ChainedHashTable.h:241
double load(void) const
the load factor
bool empty(void) const
true if there are no keys
const Pair & const_reference
a constant reference to an item
Definition ChainedHashTable.h:308
std::size_t restructures(void) const
the number of restructurings so far
void insert(const K &k, const V &v)
associates the value to the key
std::vector< K > chain(std::size_t i) const
the keys of the list , from its head
bool contains(const K &k) const
true if the key is there
K Key
the type of the keys
Definition ChainedHashTable.h:107
const_iterator cbegin(void) const
the constant iterator on the first item
Definition ChainedHashTable.h:321
const_iterator end(void) const
the iterator past the last item
Definition ChainedHashTable.h:317
std::size_t size_type
the type of the sizes
Definition ChainedHashTable.h:302
std::size_t size(void) const
the number of keys
const Pair & reference
a reference to an item
Definition ChainedHashTable.h:306
std::size_t moved(void) const
the number of pairs moved by the restructurings so far
const_iterator begin(void) const
the iterator on the first item
Definition ChainedHashTable.h:313
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,...
const_iterator iterator
the iterator on the items
Definition ChainedHashTable.h:310
std::ptrdiff_t difference_type
the type of the distances between two iterators
Definition ChainedHashTable.h:304
V Value
the type of the values
Definition ChainedHashTable.h:108
std::size_t probes(void) const
the cells of the list examined by the last operation, plus one for the nil that ends an unsuccessful ...
const_iterator cend(void) const
the constant iterator past the last item
Definition ChainedHashTable.h:323
ChainedHashTable(std::size_t m, bool restructure=false, H h=H())
the empty table of lists, which restructures itself or not, at the loads 2 and
std::optional< V > lookup(const K &k) const
the value of the key , or nothing
std::size_t capacity(void) const
the number of lists
void remove(const K &k)
removes the key , if it is there, from its list; the table, if it restructures itself,...
Pair value_type
the type of the items, for the standard library
Definition ChainedHashTable.h:300
void forEach(F &&f) const
the foreach of the book: f( k , v ) on the pairs, list after list, time
ChainedHashTable(std::size_t m, double g, double s, H h=H())
the empty table of lists, which doubles when its load exceeds and halves, down to ,...
a SEQUENCE realized as a bidirectional circular list with a sentinel, its cells from a pool if Pooled
Definition List.h:118
Cell * Pos
Definition List.h:132
#define ADS_NOINLINE
a function never inlined
Definition Portable.h:99
Chain
how a ChainedHashTable keeps its lists
Definition ChainedHashTable.h:92
@ MOVE_TO_FRONT
also the key found by lookup() goes to the head
Definition ChainedHashTable.h:94
@ SORTED
the keys of a list in increasing order
Definition ChainedHashTable.h:95
@ FRONT
a new key at the head, nothing moves
Definition ChainedHashTable.h:93