ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
RearCoding.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*--------------------------- File RearCoding.h ----------------------------*/
3/*--------------------------------------------------------------------------*/
86/*--------------------------------------------------------------------------*/
87/*----------------------------- DEFINITIONS --------------------------------*/
88/*--------------------------------------------------------------------------*/
89
90#ifndef __ADS_RearCoding
91 #define __ADS_RearCoding
92/* self-identification: #endif constant */
93
94/*--------------------------------------------------------------------------*/
95/*------------------------------ INCLUDES ----------------------------------*/
96/*--------------------------------------------------------------------------*/
97
98#include "ADS/Contract.h"
100#include "ADS/memory/Prefetch.h"
104
105#include <array>
106#include <cstddef>
107#include <cstdint>
108#include <string>
109#include <string_view>
110#include <utility>
111#include <vector>
112
113/*--------------------------------------------------------------------------*/
114/*--------------------------- NAMESPACE ------------------------------------*/
115/*--------------------------------------------------------------------------*/
116
117namespace ADS
118{
119
122using RearPair = std::pair< std::size_t , std::string >;
123
140[[nodiscard]] inline std::vector< RearPair >
141rearCode( const std::vector< std::string > & D );
142
159[[nodiscard]] inline std::vector< std::string >
160rearDecode( const std::vector< RearPair > & R );
161
162/*--------------------------------------------------------------------------*/
163/*----------------------- CLASS RearCodedDictionary ------------------------*/
164/*--------------------------------------------------------------------------*/
165
169{
170
171/*--------------------------------------------------------------------------*/
172 public:
174 RearCodedDictionary( void ) = default;
175
204 explicit RearCodedDictionary( const std::vector< std::string > & D ,
205 std::size_t b = 16 );
206
208 [[nodiscard]] std::size_t size( void ) const;
209
211 [[nodiscard]] bool empty( void ) const;
212
214 [[nodiscard]] std::size_t bucketSize( void ) const;
215
232 [[nodiscard]] std::string access( std::size_t i ) const;
233
237 [[nodiscard]] std::size_t lookup( std::string_view Q ) const;
238
267 [[nodiscard]] std::size_t lexicographicPosition( std::string_view Q ) const;
268
272 [[nodiscard]] std::size_t prefixEnd( std::string_view P ) const;
273
276 [[nodiscard]] std::pair< std::size_t , std::size_t >
277 prefixRange( std::string_view P ) const;
278
281 [[nodiscard]] std::size_t codeBytes( void ) const;
282
285 [[nodiscard]] std::size_t bytes( void ) const;
286
287/*--------------------------------------------------------------------------*/
288 private:
290 static constexpr int kMax = 11;
291
293 static constexpr int kWide = 12;
294
297 static constexpr std::size_t kHead = 16;
298
302 struct Code
303 {
304 std::array< std::uint8_t , 256 > len{};
305 std::array< std::uint32_t , 256 > word{};
306 std::vector< std::uint16_t > table;
309 std::vector< std::uint32_t > multi;
310
313 void build( const std::array< std::uint64_t , 256 > & f );
314 };
315
319 [[nodiscard]] std::uint64_t peek( std::size_t pos ) const;
320
321 [[nodiscard]] unsigned decode( const Code & c , std::size_t & pos ) const;
322
325 [[nodiscard]] std::size_t getLength( const Code & c ,
326 std::size_t & pos ) const;
327
329 void putLength( const Code & c , std::size_t v );
330
333 [[nodiscard]] static std::uint64_t prefix8( std::string_view s );
334
337 [[nodiscard]] unsigned byte( std::size_t k , std::size_t j ) const;
338
341 void readRest( std::string & s , std::size_t len , std::size_t & pos ) const;
342
349 template< bool S >
350 [[nodiscard]] unsigned follow( std::string_view Q , std::size_t & l ,
351 std::size_t a , std::size_t n ,
352 std::size_t & pos ) const;
353
356 [[nodiscard]] std::string head( std::size_t k , std::size_t & pos ) const;
357
361 [[nodiscard]] std::size_t rank( std::string_view Q , bool upper ,
362 bool * eq = nullptr ) const;
363
364 std::size_t f_n = 0;
365 std::size_t f_b = 16;
366 BitVector f_C;
367 EliasFano f_P;
368 std::string f_common;
369 std::vector< std::uint64_t > f_head;
370 Code f_char;
371 Code f_rear;
372 Code f_size;
373
374 }; // end( class RearCodedDictionary )
375
376/*--------------------------------------------------------------------------*/
377
378} // end( namespace ADS )
379
380/*--------------------------------------------------------------------------*/
381/*-------------------------- IMPLEMENTATION --------------------------------*/
382/*--------------------------------------------------------------------------*/
383
384#include "ADS/string/impl/RearCoding.tpp"
385
386/*--------------------------------------------------------------------------*/
387
388#endif /* RearCoding.h included */
389
390/*--------------------------------------------------------------------------*/
391/*------------------------- End File RearCoding.h --------------------------*/
392/*--------------------------------------------------------------------------*/
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 Elias-Fano representation of a non-decreasing sequence of integers in (chapters 11,...
The front coding of a sorted dictionary of strings, beyond the book: adjacent strings share a prefix,...
The code of Huffman of a string of bytes as the fast coders do it, beyond the canonical code of chapt...
The prefetch of a line of the cache, beyond the book: ADS::prefetch( p ) asks the processor to bring ...
std::size_t bytes(void) const
all the bytes: the coding, the places and the samples of the buckets, and the codes with their tables
std::size_t lexicographicPosition(std::string_view Q) const
the number of strings smaller than
bool empty(void) const
whether there is no string
std::size_t codeBytes(void) const
the bytes of the coding, with the first strings and the lengths
std::size_t bucketSize(void) const
the strings of a bucket,
RearCodedDictionary(void)=default
the empty dictionary
std::size_t size(void) const
the number of strings
RearCodedDictionary(const std::vector< std::string > &D, std::size_t b=16)
the rear coding of in buckets of strings
std::pair< std::size_t, std::size_t > prefixRange(std::string_view P) const
the range of the strings prefixed by , by lexicographicPosition() and prefixEnd()
std::size_t prefixEnd(std::string_view P) const
the number of strings smaller than , i.e., smaller than or prefixed by it, by the search of lexicogr...
std::size_t lookup(std::string_view Q) const
the place of , size() if it is not a string of the dictionary, by the search of lexicographicPosition...
std::string access(std::size_t i) const
the string , decoded from the first string of its bucket
std::vector< RearPair > rearCode(const std::vector< std::string > &D)
the rear coding of , a pair per string
std::vector< std::string > rearDecode(const std::vector< RearPair > &R)
the strings of the rear coding
std::pair< std::size_t, std::string > RearPair
a pair of the rear coding, the characters taken off the end of the string before and the rest
Definition RearCoding.h:122
BasicEliasFano< false > EliasFano
Elias-Fano with the inventories of built in the constructor, the fastest access() and nextGEQ().
Definition EliasFano.h:291
Definition ADT.h:96