ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
PGMIndex.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------------- File PGMIndex.h -----------------------------*/
3/*--------------------------------------------------------------------------*/
81/*--------------------------------------------------------------------------*/
82/*----------------------------- DEFINITIONS --------------------------------*/
83/*--------------------------------------------------------------------------*/
84
85#ifndef __ADS_PGMIndex
86 #define __ADS_PGMIndex
87/* self-identification: #endif constant */
88
89/*--------------------------------------------------------------------------*/
90/*------------------------------ INCLUDES ----------------------------------*/
91/*--------------------------------------------------------------------------*/
92
93#include "ADS/Contract.h"
94#include "ADS/Portable.h"
95#include "ADS/Wide.h"
98#include "ADS/memory/Prefetch.h"
99
100#include <bit>
101#include <cstddef>
102#include <cstdint>
103#include <string_view>
104#include <type_traits>
105#include <vector>
106
107/*--------------------------------------------------------------------------*/
108/*--------------------------- NAMESPACE ------------------------------------*/
109/*--------------------------------------------------------------------------*/
110
111namespace ADS
112{
113
114/*--------------------------------------------------------------------------*/
115/*---------------------------- CLASS PGMIndex ------------------------------*/
116/*--------------------------------------------------------------------------*/
117
121template< class K , std::size_t E = 64 , std::size_t R = 4 >
122 requires std::is_arithmetic_v< K >
124{
125
126 static_assert( ( E >= 1 ) && ( R >= 1 ) , "the errors are at least 1" );
127
128/*--------------------------------------------------------------------------*/
129 public:
130 using Item = K;
131
133 PGMIndex( void ) = default;
134
171 explicit PGMIndex( const std::vector< K > & A );
172
203 [[nodiscard]] std::size_t lowerBound( const K & v ) const;
204
206 [[nodiscard]] bool contains( const K & v ) const;
207
210 [[nodiscard]] const K & operator[]( std::size_t i ) const;
211
213 [[nodiscard]] std::size_t size( void ) const;
214
216 [[nodiscard]] bool empty( void ) const;
217
219 [[nodiscard]] std::size_t segments( void ) const;
220
222 [[nodiscard]] int height( void ) const;
223
225 [[nodiscard]] std::size_t bytes( void ) const;
226
227/*----------------------------- THE PERSISTENCE ----------------------------*/
228
230 static constexpr std::string_view persistName = "PGMIndex";
231
233 [[nodiscard]] static constexpr std::uint64_t persistTag( void ) {
234 return( detail::persistMix( { sizeof( K ) , std::is_signed_v< K > ,
235 std::is_floating_point_v< K > , E , R } ) );
236 }
237
240 template< class A >
241 void persist( A & a );
242
243/*--------------------------------------------------------------------------*/
244 private:
247 struct Line
248 {
249 double icpt;
250 double slope;
251 using persist_unit = std::uint64_t;
252 };
253
257 struct Level
258 {
259 std::vector< std::uint64_t > key;
260 std::vector< Line > line;
261 std::vector< std::uint32_t > start;
262
264 template< class A >
265 void persist( A & a ) {
266 a( key , line , start );
267 a.require( ( line.size() == key.size() ) &&
268 ( start.size() == key.size() + 1 ) ,
269 "a level of a PGMIndex" );
270 }
271 };
272
274 [[nodiscard]] static std::uint64_t ord( const K & k );
275
278 static Level approximate( const std::vector< std::uint64_t > & x ,
279 const std::vector< std::uint32_t > & y ,
280 std::int64_t e , std::size_t total );
281
284 [[nodiscard]] static std::size_t predict( const Level & l , std::size_t s ,
285 std::uint64_t x );
286
287 std::vector< K , HugePageAllocator< K > > f_A;
288 std::vector< Level > f_L;
289
290 }; // end( class PGMIndex )
291
292/*--------------------------------------------------------------------------*/
293
294} // end( namespace ADS )
295
296/*--------------------------------------------------------------------------*/
297/*-------------------------- IMPLEMENTATION --------------------------------*/
298/*--------------------------------------------------------------------------*/
299
300#include "ADS/search/impl/PGMIndex.tpp"
301
302/*--------------------------------------------------------------------------*/
303
304#endif /* PGMIndex.h included */
305
306/*--------------------------------------------------------------------------*/
307/*-------------------------- End File PGMIndex.h ---------------------------*/
308/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
An allocator for the large blocks of a structure, beyond the book: a request of at least one huge pag...
A file mapped in memory, shared by the structures that are read from it in place [see Persistence....
The primitives of the processor that the compilers spell each in their own way, in one form for all: ...
The prefetch of a line of the cache, beyond the book: ADS::prefetch( p ) asks the processor to bring ...
The arithmetic of two words that C++20 does not spell, in one form for every compiler: the product of...
PGMIndex(const std::vector< K > &A)
the index on the sorted items of , a level of segments of error on the distinct keys and their first...
bool empty(void) const
true if there are no items
std::size_t bytes(void) const
the bytes of the index, the items aside
void persist(A &a)
the members written to, or read from, the archive [see Persistence.h]
std::size_t segments(void) const
the segments of the last level
bool contains(const K &v) const
true if is an item, by lowerBound( v )
static constexpr std::string_view persistName
the name of the structure in a file [see Persistence.h]
Definition PGMIndex.h:230
K Item
the type of the items
Definition PGMIndex.h:130
const K & operator[](std::size_t i) const
the item of place
static constexpr std::uint64_t persistTag(void)
the type of the keys and the errors, in a file
Definition PGMIndex.h:233
std::size_t lowerBound(const K &v) const
the first place of an item not smaller than , size() if none
int height(void) const
the levels of segments
PGMIndex(void)=default
an empty index
std::size_t size(void) const
the number of the items
Definition ADT.h:96