ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
PartitionedEliasFano.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*----------------------- File PartitionedEliasFano.h ----------------------*/
3/*--------------------------------------------------------------------------*/
77/*--------------------------------------------------------------------------*/
78/*----------------------------- DEFINITIONS --------------------------------*/
79/*--------------------------------------------------------------------------*/
80
81#ifndef __ADS_PartitionedEliasFano
82 #define __ADS_PartitionedEliasFano
83/* self-identification: #endif constant */
84
85/*--------------------------------------------------------------------------*/
86/*------------------------------ INCLUDES ----------------------------------*/
87/*--------------------------------------------------------------------------*/
88
89#include "ADS/Contract.h"
92
93#include <algorithm>
94#include <array>
95#include <bit>
96#include <cstddef>
97#include <cstdint>
98#include <span>
99#include <string_view>
100#include <vector>
101
102/*--------------------------------------------------------------------------*/
103/*--------------------------- NAMESPACE ------------------------------------*/
104/*--------------------------------------------------------------------------*/
105
106namespace ADS
107{
108
109/*--------------------------------------------------------------------------*/
110/*----------------------- CLASS PartitionedEliasFano -----------------------*/
111/*--------------------------------------------------------------------------*/
112
117{
118
119/*--------------------------------------------------------------------------*/
120 public:
122 PartitionedEliasFano( void ) = default;
123
126 explicit PartitionedEliasFano( std::span< const std::uint64_t > x );
127
158 PartitionedEliasFano( std::span< const std::uint64_t > x , std::uint64_t u );
159
161 [[nodiscard]] std::size_t size( void ) const { return( f_n ); }
162
164 [[nodiscard]] bool empty( void ) const { return( f_n == 0 ); }
165
167 [[nodiscard]] std::uint64_t universe( void ) const { return( f_u ); }
168
192 [[nodiscard]] std::uint64_t access( std::size_t i ) const;
193
196 [[nodiscard]] std::uint64_t operator[]( std::size_t i ) const {
197 return( access( i ) );
198 }
199
230 [[nodiscard]] std::size_t nextGEQ( std::uint64_t x ) const;
231
233 [[nodiscard]] bool contains( std::uint64_t x ) const;
234
237 [[nodiscard]] std::array< std::size_t , 3 > kinds( void ) const;
238
241 [[nodiscard]] std::size_t sizeInBits( void ) const;
242
243/*----------------------------- THE PERSISTENCE ----------------------------*/
244
246 static constexpr std::string_view persistName = "PartitionedEliasFano";
247
250 static constexpr std::uint32_t persistVersion = 2;
251
253 [[nodiscard]] static constexpr std::uint64_t persistTag( void ) {
254 return( detail::persistMix( { kB , kS , kSample } ) );
255 }
256
259 template< class A >
260 void persist( A & a );
261
262/*------------------------- THE STANDARD INTERFACE -------------------------*/
263
265 using value_type = std::uint64_t;
267 using size_type = std::size_t;
269 using difference_type = std::ptrdiff_t;
271 using reference = std::uint64_t;
273 using const_reference = std::uint64_t;
279
281 [[nodiscard]] const_iterator begin( void ) const {
282 return( const_iterator( this , 0 ) );
283 }
284
285 [[nodiscard]] const_iterator end( void ) const {
286 return( const_iterator( this , f_n ) );
287 }
288
289 [[nodiscard]] const_iterator cbegin( void ) const { return( begin() ); }
291 [[nodiscard]] const_iterator cend( void ) const { return( end() ); }
292
293/*--------------------------------------------------------------------------*/
294 private:
295 static constexpr std::size_t kB = 128;
296 static constexpr std::size_t kS = 16;
297 static constexpr std::size_t kSample = 64;
298
300 enum Kind {
301 FULL = 0 ,
302 VECTOR = 1 ,
303 ELIAS = 2
304 };
305
308 struct Code
309 {
310 Kind kind;
311 std::uint64_t bits;
312 int ell;
313 };
314 [[nodiscard]] static Code code( std::uint64_t m , std::uint64_t u );
315
318 struct Record
319 {
320 std::uint64_t b;
321 std::size_t p;
322 std::size_t sample;
323 unsigned form;
324 };
325 [[nodiscard]] Record record( std::size_t j ) const;
326
328 [[nodiscard]] std::uint64_t relBase( std::size_t j ) const {
329 return( f_rec[ j * f_s ] & f_mb );
330 }
331
335 template< bool One >
336 [[nodiscard]] std::size_t select( std::size_t p , std::size_t k ) const;
337
339 [[nodiscard]] std::size_t ones( std::size_t p , std::size_t q ) const;
340
342 template< class T >
343 using Array = std::vector< T , MappableAllocator< T > >;
344
345 std::size_t f_n = 0;
346 std::uint64_t f_u = 0;
347 std::uint64_t f_last = 0;
348 BitVector f_codes;
349 Array< std::uint64_t > f_rec;
350 Array< std::uint64_t > f_sup;
351 Array< std::uint32_t > f_bkt;
352 int f_shift = 0;
353 std::size_t f_s = 1;
354 int f_wb = 1 , f_wo = 1 , f_ws = 1;
355 int f_sh = 1;
356 std::uint64_t f_mb = 1 , f_mo = 1 , f_ms = 1;
357
358 }; // end( class PartitionedEliasFano )
359
360/*--------------------------------------------------------------------------*/
361
362} // end( namespace ADS )
363
364/*--------------------------------------------------------------------------*/
365/*-------------------------- IMPLEMENTATION --------------------------------*/
366/*--------------------------------------------------------------------------*/
367
368#include "ADS/succinct/impl/PartitionedEliasFano.tpp"
369
370/*--------------------------------------------------------------------------*/
371
372#endif /* PartitionedEliasFano.h included */
373
374/*--------------------------------------------------------------------------*/
375/*--------------------- End File PartitionedEliasFano.h --------------------*/
376/*--------------------------------------------------------------------------*/
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,...
A file mapped in memory, shared by the structures that are read from it in place [see Persistence....
const_iterator cbegin(void) const
the same as begin()
Definition PartitionedEliasFano.h:289
std::ptrdiff_t difference_type
the type of the distance of two places
Definition PartitionedEliasFano.h:269
std::uint64_t universe(void) const
the bound of the items
Definition PartitionedEliasFano.h:167
std::size_t size(void) const
the number of items,
Definition PartitionedEliasFano.h:161
std::uint64_t operator[](std::size_t i) const
the item , as access()
Definition PartitionedEliasFano.h:196
SubscriptIterator< PartitionedEliasFano, std::uint64_t > const_iterator
the constant iterator, random access
Definition PartitionedEliasFano.h:275
std::uint64_t value_type
the type of an item
Definition PartitionedEliasFano.h:265
const_iterator begin(void) const
the iterator on the first item
Definition PartitionedEliasFano.h:281
std::size_t size_type
the type of a size
Definition PartitionedEliasFano.h:267
bool contains(std::uint64_t x) const
whether is in the sequence, by nextGEQ()
PartitionedEliasFano(void)=default
the empty sequence
const_iterator end(void) const
the iterator past the last item
Definition PartitionedEliasFano.h:285
std::size_t nextGEQ(std::uint64_t x) const
the place of the first item , size() if none
std::uint64_t access(std::size_t i) const
the item
static constexpr std::uint32_t persistVersion
the version of the layout in a file: 2, that of the records of whole words and of the buckets
Definition PartitionedEliasFano.h:250
PartitionedEliasFano(std::span< const std::uint64_t > x)
the sequence , with the universe
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
static constexpr std::uint64_t persistTag(void)
the items of a block, in a file
Definition PartitionedEliasFano.h:253
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition PartitionedEliasFano.h:246
PartitionedEliasFano(std::span< const std::uint64_t > x, std::uint64_t u)
the sequence in
bool empty(void) const
whether there is no item
Definition PartitionedEliasFano.h:164
std::uint64_t const_reference
an item, returned by value
Definition PartitionedEliasFano.h:273
std::size_t sizeInBits(void) const
the bits of the codes, of the records, of the superblocks and of the buckets
std::array< std::size_t, 3 > kinds(void) const
the numbers of the full blocks, of those coded as vectors and of those coded by Elias-Fano
const_iterator cend(void) const
the same as end()
Definition PartitionedEliasFano.h:291
const_iterator iterator
the same as const_iterator
Definition PartitionedEliasFano.h:278
std::uint64_t reference
an item, returned by value
Definition PartitionedEliasFano.h:271
the random-access constant iterator on the items T of the owner O, read by ( *o )[ i ]
Definition BitVector.h:372
Definition ADT.h:96