123#ifndef __ADS_UniversalHashing
124 #define __ADS_UniversalHashing
147#include <string_view>
186 [[nodiscard]] std::uint64_t
operator()( std::uint64_t k )
const;
189 [[nodiscard]] std::uint64_t
p(
void )
const {
return( f_p ); }
192 [[nodiscard]] std::uint64_t
a(
void )
const {
return( f_a ); }
195 [[nodiscard]] std::uint64_t
b(
void )
const {
return( f_b ); }
198 [[nodiscard]] std::uint64_t
m(
void )
const {
return( f_m ); }
204 a( f_p , f_a , f_b , f_m );
205 a.require( ( f_p >= 2 ) && ( f_p < ( std::uint64_t( 1 ) << 63 ) ) &&
206 ( f_a >= 1 ) && ( f_a < f_p ) && ( f_b < f_p ) && ( f_m >= 1 ) ,
207 "the parameters of a CarterWegmanHash" );
212 std::uint64_t f_p , f_a , f_b , f_m;
248 [[nodiscard]] std::uint64_t
operator()( std::uint64_t k )
const;
252 [[nodiscard]] std::uint64_t
universe(
void )
const;
256 std::vector< std::uint64_t > f_a;
280 [[nodiscard]] std::uint64_t
operator()( std::uint64_t k )
const;
285 std::uint64_t f_mask;
315 [[nodiscard]] std::uint64_t
operator()( std::string_view s )
const;
329template<
class K = std::u
int64_t ,
class Code = std::hash< K > >
339 Code code = Code() );
359 [[nodiscard]] std::size_t
place(
const K & k , std::size_t m )
const;
362 [[nodiscard]] std::uint64_t
multiplier(
void )
const {
return( f_z ); }
401 [[nodiscard]] std::uint64_t
405 [[nodiscard]] std::size_t
parts(
void )
const {
return( f_Z.size() ); }
408 std::vector< std::uint64_t > f_Z;
409 std::uint64_t f_lo , f_hi;
447 [[nodiscard]] std::uint64_t
454 [[nodiscard]] std::uint64_t
operator()( std::string_view s )
const;
467template<
class K ,
class V ,
class H = std::hash< K > >
482 [[nodiscard]] std::optional< V >
lookup(
const K & k )
const;
501 void insert(
const K & k ,
const V & v );
511 [[nodiscard]] std::size_t
size(
void )
const;
514 [[nodiscard]] std::size_t
maxLoad(
void )
const;
521 using Bucket = std::vector< std::pair< K , V > >;
549 : f_T( T ) , f_b( b ) {
555 const auto & e = ( *f_T )[ f_b ][ f_i ];
556 return(
reference( e.first , e.second ) );
573 return( ( f_b == o.f_b ) && ( f_i == o.f_i ) );
578 void forward(
void ) {
579 while( ( f_b < f_T->
size() ) && ( f_i >= ( *f_T )[ f_b ].
size() ) ) {
585 const std::vector< Bucket > * f_T =
nullptr;
622 [[nodiscard]] std::size_t list(
const K & k ,
int i )
const;
625 [[nodiscard]] std::optional< std::pair< std::size_t , std::size_t > >
626 find(
const K & k )
const;
630 [[nodiscard]]
bool placed(
const K & k )
const;
633 std::vector< Bucket > f_T;
635 std::vector< TabulationHash > f_g;
648#include "ADS/dictionary/impl/UniversalHashing.tpp"
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 arithmetic of section 17.2 and of exercises 17.1-17.3, on unsigned integers of 64 bits:
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
Hashing with random tables, beyond the book:
Random numbers as Knuth treats them (chapter 3 of The Art of Computer Programming),...
CarterWegmanHash(std::uint64_t m, std::uint64_t seed=1)
a function drawn from with , from the seed
std::uint64_t b(void) const
the addend
Definition UniversalHashing.h:195
std::uint64_t a(void) const
the multiplier
Definition UniversalHashing.h:192
std::uint64_t p(void) const
the prime
Definition UniversalHashing.h:189
std::uint64_t m(void) const
the size of the range
Definition UniversalHashing.h:198
CarterWegmanHash(void)
the function into one place drawn from the seed 1, to be read from a file [see Persistence....
Definition UniversalHashing.h:169
std::uint64_t operator()(std::uint64_t k) const
, the product computed with no overflow [see mulMod()]
void persist(A &a)
the parameters written to, or read from, the archive [see Persistence.h]
Definition UniversalHashing.h:203
CarterWegmanHash(std::uint64_t p, std::uint64_t a, std::uint64_t b, std::uint64_t m)
the function of the given parameters
std::uint64_t operator()(std::span< const std::uint64_t > x) const
, in time
std::size_t parts(void) const
the number of parts
Definition UniversalHashing.h:405
CompoundHash(std::size_t r, std::uint64_t seed=1)
a function of tuples of words, its multipliers from the seed
the iterator on the pairs, table after table and list after list
Definition UniversalHashing.h:531
bool operator==(const const_iterator &o) const
equal on the same place of the same list
Definition UniversalHashing.h:572
const_iterator & operator++(void)
to the next pair
Definition UniversalHashing.h:559
const_iterator operator++(int)
to the next pair, returning the iterator before the step
Definition UniversalHashing.h:565
reference operator*(void) const
the pair
Definition UniversalHashing.h:554
PairRef< const K &, const V & > reference
a reference to an item
Definition UniversalHashing.h:534
std::input_iterator_tag iterator_category
the category of the iterator
Definition UniversalHashing.h:542
std::ptrdiff_t difference_type
the type of the distances between two iterators
Definition UniversalHashing.h:538
std::forward_iterator_tag iterator_concept
the concept of the iterator, for C++20
Definition UniversalHashing.h:540
const_iterator(const std::vector< Bucket > *T, std::size_t b)
on the first pair from the list of the lists
Definition UniversalHashing.h:548
std::pair< K, V > value_type
the type of the items, for the standard library
Definition UniversalHashing.h:536
const_iterator(void)=default
the end of no table
std::optional< V > lookup(const K &k) const
the value of the key , or nothing, from its lists
K key_type
the type of the keys
Definition UniversalHashing.h:593
void remove(const K &k)
removes the key , if it is there, from its list
DLeftHashTable(std::size_t m, int d, std::uint64_t seed=1, H h=H())
tables of lists each,
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 UniversalHashing.h:591
V mapped_type
the type of the values
Definition UniversalHashing.h:595
reference const_reference
a constant reference to an item
Definition UniversalHashing.h:603
std::size_t size_type
the type of the sizes
Definition UniversalHashing.h:597
const_iterator begin(void) const
the iterator on the first item
Definition UniversalHashing.h:608
V Value
the type of the values
Definition UniversalHashing.h:474
K Key
the type of the keys
Definition UniversalHashing.h:473
std::size_t maxLoad(void) const
the length of the longest list
const_iterator cbegin(void) const
the constant iterator on the first item
Definition UniversalHashing.h:616
std::ptrdiff_t difference_type
the type of the distances between two iterators
Definition UniversalHashing.h:599
PairRef< const K &, const V & > reference
a reference to an item
Definition UniversalHashing.h:601
const_iterator end(void) const
the iterator past the last item
Definition UniversalHashing.h:612
const_iterator cend(void) const
the constant iterator past the last item
Definition UniversalHashing.h:618
bool contains(const K &k) const
true if the key is there
const_iterator iterator
the iterator on the items
Definition UniversalHashing.h:605
void insert(const K &k, const V &v)
associates the value to the key
int tables(void) const
the number of tables
DotProductHash(std::uint64_t m, std::vector< std::uint64_t > a)
the function of the digits
std::uint64_t universe(void) const
the size of the universe, or 0 if it exceeds
std::uint64_t operator()(std::uint64_t k) const
DotProductHash(std::uint64_t m, int r, std::uint64_t seed=1)
a function with random digits , from the seed
std::uint64_t operator()(const K &k) const
the product , whose high bits are the hash
static MultiplicativeHash ofMultiplier(std::uint64_t z, Code code=Code())
the function of the multiplier
std::size_t place(const K &k, std::size_t m) const
the place of in a table of places, the high bits of [see PlaceHash in TableSize....
std::uint64_t multiplier(void) const
the multiplier
Definition UniversalHashing.h:362
MultiplicativeHash(std::uint64_t seed=1, Code code=Code())
a function with a random odd of 64 bits, from the seed
std::uint64_t operator()(std::uint64_t k) const
, a product and a shift
MultiplyShiftHash(int h, int l, std::uint64_t seed=1)
a function with a random odd , from the seed
static MultiplyShiftHash ofMultiplier(int h, int l, std::uint64_t a)
the function of the multiplier
std::uint64_t operator()(std::span< const std::uint64_t > x) const
of an array of words, each reduced first to 60 bits by the multiplicative hashing [see Multiplicative...
SequenceHash(std::uint64_t seed=1)
a function with a random point and a random odd multiplier for the reduction of the words,...
std::uint64_t operator()(std::string_view s) const
of a string, its bytes taken as they are: two distinct strings, the longer of bytes,...
StringHash(std::uint64_t seed=1)
a function with a random point , from the seed
std::uint64_t operator()(std::string_view s) const
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
#define ADS_NO_UNIQUE_ADDRESS
an empty member that takes no storage, by the attribute that does so (the standard one is accepted bu...
Definition Portable.h:81