ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
RecSplit.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------------- File RecSplit.h -----------------------------*/
3/*--------------------------------------------------------------------------*/
146/*--------------------------------------------------------------------------*/
147/*----------------------------- DEFINITIONS --------------------------------*/
148/*--------------------------------------------------------------------------*/
149
150#ifndef __ADS_RecSplit
151 #define __ADS_RecSplit
152/* self-identification: #endif constant */
153
154/*--------------------------------------------------------------------------*/
155/*------------------------------ INCLUDES ----------------------------------*/
156/*--------------------------------------------------------------------------*/
157
158#include "ADS/Contract.h"
162
163#include <algorithm>
164#include <array>
165#include <bit>
166#include <cmath>
167#include <cstddef>
168#include <cstdint>
169#include <memory>
170#include <stdexcept>
171#include <string_view>
172#include <type_traits>
173#include <utility>
174#include <vector>
175
176/*--------------------------------------------------------------------------*/
177/*--------------------------- NAMESPACE ------------------------------------*/
178/*--------------------------------------------------------------------------*/
179
180namespace ADS
181{
182
183namespace detail
184{
185
189struct RecSplitTables
190{
191 std::vector< std::uint8_t > rice;
192 std::vector< std::uint32_t > low;
193 std::vector< std::uint16_t > nodes;
194 };
195
198[[nodiscard]] int recSplitSelect( std::uint64_t x , int k );
199
204class RecSplitSequence
205{
206 public:
208 RecSplitSequence( void ) = default;
209
211 explicit RecSplitSequence( const std::vector< std::uint64_t > & x );
212
214 [[nodiscard]] std::uint64_t access( std::size_t i ) const;
215
217 [[nodiscard]] std::pair< std::uint64_t , std::uint64_t >
218 pair( std::size_t i ) const;
219
221 [[nodiscard]] std::size_t sizeInBits( void ) const;
222
224 template< class A >
225 void persist( A & a ) {
226 a( f_l , f_low , f_high , f_inv );
227 a.require( ( f_l >= 0 ) && ( f_l < 64 ) , "a sequence of a RecSplit" );
228 }
229
230 private:
232 [[nodiscard]] std::size_t select( std::size_t i ) const;
233
235 [[nodiscard]] std::uint64_t low( std::size_t i ) const;
236
237 int f_l = 0;
238 std::vector< std::uint64_t > f_low;
240 std::vector< std::uint64_t > f_high;
241 std::vector< std::uint64_t > f_inv;
242 };
243
244} // end( namespace detail )
245
246/*--------------------------------------------------------------------------*/
247/*----------------------------- CLASS RecSplit -----------------------------*/
248/*--------------------------------------------------------------------------*/
249
252template< class T , unsigned L = 8 , class H = DefaultHash< T > >
254{
255
256 static_assert( ( L >= 1 ) && ( L <= 24 ) , "RecSplit: 1 <= L <= 24" );
257
258/*--------------------------------------------------------------------------*/
259 public:
261 RecSplit( void ) : RecSplit( std::vector< T >() ) { }
262
263 using Key = T;
264
299 explicit RecSplit( const std::vector< T > & keys , std::size_t b = 100 ,
300 std::uint64_t seed = 1 , H h = H() );
301
326 [[nodiscard]] std::size_t operator()( const T & k ) const;
327
329 [[nodiscard]] std::size_t size( void ) const;
330
332 [[nodiscard]] bool empty( void ) const;
333
336 [[nodiscard]] std::size_t bits( void ) const;
337
339 [[nodiscard]] std::size_t buckets( void ) const;
340
342 [[nodiscard]] std::size_t trials( void ) const;
343
344/*----------------------------- THE PERSISTENCE ----------------------------*/
345
347 static constexpr std::string_view persistName = "RecSplit";
348
350 [[nodiscard]] static constexpr std::uint64_t persistTag( void ) {
351 return( detail::persistMix( { sizeof( T ) , L } ) );
352 }
353
356 template< class A >
357 void persist( A & a );
358
359/*--------------------------------------------------------------------------*/
360 private:
361 static constexpr std::size_t kMaxTrials = 100;
362 static constexpr std::size_t kMaxBucket = 4096;
364 static constexpr std::size_t kLower =
365 std::max< std::size_t >( 2 , ( 35 * L + 50 + 99 ) / 100 ) * L;
366 static constexpr std::size_t kUpper =
367 ( L >= 7 ? ( 21 * L + 90 + 99 ) / 100 : 2 ) * kLower;
368
370 [[nodiscard]] static const detail::RecSplitTables & tables( void );
371
373 [[nodiscard]] static constexpr std::size_t left( std::size_t m );
374
377 [[nodiscard]] static std::uint64_t node( std::uint64_t h , std::uint64_t x ,
378 unsigned d );
379
381 [[nodiscard]] static std::size_t remap( std::uint64_t g , std::size_t m );
382
384 [[nodiscard]] std::uint64_t base( const T & k ) const;
385
387 [[nodiscard]] std::uint64_t window( std::uint64_t at ) const;
388
390 [[nodiscard]] std::uint64_t skipOnes( std::uint64_t at ,
391 std::size_t c ) const;
392
396 static void split( std::uint64_t * K , std::uint64_t * S , std::size_t m ,
397 unsigned d , std::vector< std::uint64_t > & seeds ,
398 std::vector< std::uint8_t > & rice );
399
402 bool build( const std::vector< std::uint64_t > & B , std::size_t b );
403
404 std::uint64_t f_seed;
405 std::size_t f_n = 0;
406 std::size_t f_nb = 0;
408 std::vector< std::uint64_t , MappableAllocator< std::uint64_t > > f_code;
410 detail::RecSplitSequence f_keys;
412 detail::RecSplitSequence f_place;
413 std::uint64_t f_dk = 0;
414 std::int64_t f_dp = 0;
416 std::uint64_t f_beta = 0;
417 const detail::RecSplitTables * f_t = nullptr;
418 std::size_t f_trials = 0;
419 H f_h;
420
421 }; // end( class RecSplit )
422
423/*--------------------------------------------------------------------------*/
424
425} // end( namespace ADS )
426
427/*--------------------------------------------------------------------------*/
428/*-------------------------- IMPLEMENTATION --------------------------------*/
429/*--------------------------------------------------------------------------*/
430
431#include "ADS/dictionary/impl/RecSplit.tpp"
432
433/*--------------------------------------------------------------------------*/
434
435#endif /* RecSplit.h included */
436
437/*--------------------------------------------------------------------------*/
438/*-------------------------- End File RecSplit.h ---------------------------*/
439/*--------------------------------------------------------------------------*/
The vector of bits on which the succinct structures and the integer codes of ADS are built: the bits ...
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....
std::size_t size(void) const
the number of keys
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
bool empty(void) const
true if there are no keys
RecSplit(void)
the function of no key
Definition RecSplit.h:261
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition RecSplit.h:347
std::size_t operator()(const T &k) const
the value of , in ; some value in it for a key out of
T Key
the type of the keys
Definition RecSplit.h:263
std::size_t trials(void) const
the seeds drawn by the build
RecSplit(const std::vector< T > &keys, std::size_t b=100, std::uint64_t seed=1, H h=H())
the function of the distinct keys, with keys per bucket on average
std::size_t bits(void) const
the bits of the function: the codes, the two Elias-Fano sequences with their directories and the obje...
static constexpr std::uint64_t persistTag(void)
the parameters of the layout, in a file
Definition RecSplit.h:350
std::size_t buckets(void) const
the number of buckets
Definition ADT.h:96