106#ifndef __ADS_PerfectHashing
107 #define __ADS_PerfectHashing
127#include <string_view>
152 using Key = std::uint64_t;
183 std::uint64_t seed = 1 );
198 [[nodiscard]]
bool contains( std::uint64_t k )
const;
201 [[nodiscard]] std::size_t
size(
void )
const;
204 [[nodiscard]] std::size_t
space(
void )
const;
207 [[nodiscard]] std::size_t
trials(
void )
const;
211 static constexpr std::uint64_t kEmpty = ~std::uint64_t( 0 );
212 static constexpr std::size_t kMaxTrials = 1000;
216 std::size_t offset = 0;
217 std::size_t
size = 0;
223 a( offset ,
size , h );
231 static constexpr std::string_view
persistName =
"PerfectHashTable";
246 static std::size_t
size(
const auto & o ) {
return( o.f_T.size() ); }
248 static bool occupied(
const auto & o , std::size_t i ) {
249 return( o.f_T[ i ] != kEmpty );
252 static const std::uint64_t &
read(
const auto & o , std::size_t i ) {
253 return( o.f_T[ i ] );
287 std::vector< Bucket > f_B;
288 std::vector< std::uint64_t > f_T;
290 std::size_t f_trials = 0;
301 requires( std::integral< K > ||
302 std::convertible_to< const K & , std::string_view > )
338 double c = 0 , std::uint64_t seed = 1 );
347 [[nodiscard]] std::size_t
size(
void )
const;
353 [[nodiscard]] std::size_t
trials(
void )
const;
385 [[nodiscard]]
static std::optional< std::vector< std::uint32_t > >
387 const std::vector< std::size_t > & h , std::size_t n );
423 [[nodiscard]]
static std::optional< std::vector< std::uint32_t > >
425 const std::vector< std::size_t > & h , std::size_t n );
430 static constexpr std::string_view
persistName =
"OrderedMinimalPerfectHash";
433 [[nodiscard]]
static constexpr std::uint64_t
persistTag(
void ) {
434 return( detail::persistMix( {
sizeof( K ) } ) );
444 static constexpr std::size_t kMaxTrials = 1000;
448 [[nodiscard]] std::uint64_t fingerprint(
const K & k ,
int i )
const;
451 [[nodiscard]] std::size_t vertex(
const K & k ,
int i )
const;
456 std::size_t f_block = 0;
457 std::size_t f_trials = 0;
458 std::vector< std::uint64_t > f_seed;
459 std::vector< CarterWegmanHash > f_h;
460 std::vector< std::uint32_t > f_g;
471#include "ADS/dictionary/impl/PerfectHashing.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...
A file mapped in memory, shared by the structures that are read from it in place [see Persistence....
Hashing with random tables, beyond the book:
Universal hashing, beyond the book [see HashFunctions.h for the fixed functions of section 7....
, of the class of Carter and Wegman
Definition UniversalHashing.h:165
static std::optional< std::vector< std::uint32_t > > labelAcyclicGraph(std::size_t m, const std::vector< std::size_t > &E, const std::vector< std::size_t > &h, std::size_t n)
the labeling of an acyclic graph: on the vertices such that on each edge , each tree labeled from ...
std::size_t trials(void) const
the graphs drawn by the build
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition PerfectHashing.h:430
std::size_t size(void) const
the number of keys
K Key
the type of the keys
Definition PerfectHashing.h:312
static constexpr std::uint64_t persistTag(void)
the parameters of the layout, in a file
Definition PerfectHashing.h:433
std::size_t operator()(const K &k) const
the value of , , in ; anything in it for a key out of
std::size_t vertices(void) const
the number of vertices, i.e., of values of
OrderedMinimalPerfectHash(const std::vector< K > &keys, int r=2, double c=0, std::uint64_t seed=1)
the function of the distinct keys, on or 3 functions and vertices; stands for 3 if and for 1....
static std::optional< std::vector< std::uint32_t > > labelByPeeling(std::size_t m, const std::vector< std::size_t > &E, int r, const std::vector< std::size_t > &h, std::size_t n)
on the vertices such that the of the vertices of each hyperedge add up to , by the reverse order ...
OrderedMinimalPerfectHash(void)
the function of no key
Definition PerfectHashing.h:309
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
std::uint64_t value_type
the type of the items, for the standard library
Definition PerfectHashing.h:258
bool contains(std::uint64_t k) const
whether is in , any , in time in the worst case: the key in the place of the table compared with
std::size_t space(void) const
the places of the second level,
std::size_t trials(void) const
the functions drawn by the build, of both levels
std::uint64_t Key
the type of the keys
Definition PerfectHashing.h:152
const std::uint64_t & reference
a reference to an item
Definition PerfectHashing.h:264
SlotIterator< PerfectHashTable, Places > const_iterator
the iterator on the items, constant
Definition PerfectHashing.h:268
const_iterator iterator
the iterator on the items
Definition PerfectHashing.h:270
const_iterator cbegin(void) const
the constant iterator on the first item
Definition PerfectHashing.h:281
std::size_t size_type
the type of the sizes
Definition PerfectHashing.h:260
const_iterator cend(void) const
the constant iterator past the last item
Definition PerfectHashing.h:283
const std::uint64_t & const_reference
a constant reference to an item
Definition PerfectHashing.h:266
const_iterator end(void) const
the iterator past the last item
Definition PerfectHashing.h:277
PerfectHashTable(const std::vector< std::uint64_t > &S, std::uint64_t seed=1)
the table of the keys of
std::ptrdiff_t difference_type
the type of the distances between two iterators
Definition PerfectHashing.h:262
static PerfectHashTable persistEmpty(void)
the table of no key, to be read from a file [see Persistence.h]
Definition PerfectHashing.h:148
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition PerfectHashing.h:231
std::size_t size(void) const
the number of keys
const_iterator begin(void) const
the iterator on the first item
Definition PerfectHashing.h:273
a bidirectional iterator on the occupied places of the table O, by the policy P with the static funct...
Definition Iterators.h:691
the places of the second level, for SlotIterator
Definition PerfectHashing.h:244
static bool occupied(const auto &o, std::size_t i)
whether the place holds a key
Definition PerfectHashing.h:248
static const std::uint64_t & read(const auto &o, std::size_t i)
the key of the place
Definition PerfectHashing.h:252
static std::size_t size(const auto &o)
the number of places
Definition PerfectHashing.h:246