ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
FingerprintPerfectHash.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------- File FingerprintPerfectHash.h ---------------------*/
3/*--------------------------------------------------------------------------*/
86/*--------------------------------------------------------------------------*/
87/*----------------------------- DEFINITIONS --------------------------------*/
88/*--------------------------------------------------------------------------*/
89
90#ifndef __ADS_FingerprintPerfectHash
91 #define __ADS_FingerprintPerfectHash
92/* self-identification: #endif constant */
93
94/*--------------------------------------------------------------------------*/
95/*------------------------------ INCLUDES ----------------------------------*/
96/*--------------------------------------------------------------------------*/
97
98#include "ADS/Contract.h"
101
102#include <algorithm>
103#include <array>
104#include <bit>
105#include <cmath>
106#include <cstddef>
107#include <cstdint>
108#include <stdexcept>
109#include <string_view>
110#include <type_traits>
111#include <vector>
112
113/*--------------------------------------------------------------------------*/
114/*--------------------------- NAMESPACE ------------------------------------*/
115/*--------------------------------------------------------------------------*/
116
117namespace ADS
118{
119
120/*--------------------------------------------------------------------------*/
121/*---------------------- CLASS FingerprintPerfectHash ----------------------*/
122/*--------------------------------------------------------------------------*/
123
126template< class T , class H = DefaultHash< T > >
128{
129
130/*--------------------------------------------------------------------------*/
131 public:
134 : FingerprintPerfectHash( std::vector< T >() ) { }
135
136 using Key = T;
137
166 explicit FingerprintPerfectHash( const std::vector< T > & keys ,
167 double gamma = 2 , std::uint64_t seed = 1 ,
168 H h = H() );
169
189 [[nodiscard]] std::size_t operator()( const T & k ) const;
190
192 [[nodiscard]] std::size_t size( void ) const;
193
195 [[nodiscard]] bool empty( void ) const;
196
198 [[nodiscard]] std::size_t bits( void ) const;
199
201 [[nodiscard]] std::size_t levels( void ) const;
202
203/*----------------------------- THE PERSISTENCE ----------------------------*/
204
206 static constexpr std::string_view persistName = "FingerprintPerfectHash";
207
209 [[nodiscard]] static constexpr std::uint64_t persistTag( void ) {
210 return( detail::persistMix( { sizeof( T ) , kBlock } ) );
211 }
212
215 template< class A >
216 void persist( A & a );
217
218/*--------------------------------------------------------------------------*/
219 private:
220 static constexpr std::size_t kMaxLevels = 64;
221 static constexpr std::size_t kBlock = 512;
222
224 [[nodiscard]] std::uint64_t base( const T & k ) const;
225
227 [[nodiscard]] static std::size_t place( std::uint64_t x , std::size_t i ,
228 std::size_t m );
229
231 [[nodiscard]] std::size_t rank( std::size_t g ) const;
232
233 std::uint64_t f_seed;
234 std::size_t f_n = 0;
236 std::vector< std::uint64_t , MappableAllocator< std::uint64_t > > f_bits;
237 std::vector< std::uint32_t > f_rank;
238 std::vector< std::size_t > f_at;
239 std::vector< std::size_t > f_m;
240 H f_h;
241
242 }; // end( class FingerprintPerfectHash )
243
244/*--------------------------------------------------------------------------*/
245
246} // end( namespace ADS )
247
248/*--------------------------------------------------------------------------*/
249/*-------------------------- IMPLEMENTATION --------------------------------*/
250/*--------------------------------------------------------------------------*/
251
252#include "ADS/dictionary/impl/FingerprintPerfectHash.tpp"
253
254/*--------------------------------------------------------------------------*/
255
256#endif /* FingerprintPerfectHash.h included */
257
258/*--------------------------------------------------------------------------*/
259/*--------------------- End File FingerprintPerfectHash.h ------------------*/
260/*--------------------------------------------------------------------------*/
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....
A file mapped in memory, shared by the structures that are read from it in place [see Persistence....
FingerprintPerfectHash(const std::vector< T > &keys, double gamma=2, std::uint64_t seed=1, H h=H())
the function of the distinct keys, with bits per key in each level
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
std::size_t levels(void) const
the number of levels
std::size_t bits(void) const
the bits of the function: the levels, their ranks and their sizes
std::size_t size(void) const
the number of keys
T Key
the type of the keys
Definition FingerprintPerfectHash.h:136
static constexpr std::uint64_t persistTag(void)
the parameters of the layout, in a file
Definition FingerprintPerfectHash.h:209
std::size_t operator()(const T &k) const
the value of , in ; some value in it for a key out of
bool empty(void) const
true if there are no keys
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition FingerprintPerfectHash.h:206
FingerprintPerfectHash(void)
the function of no key
Definition FingerprintPerfectHash.h:133
Definition ADT.h:96