88#ifndef __ADS_FrontCoding
89 #define __ADS_FrontCoding
104#include <string_view>
117using FrontPair = std::pair< std::size_t , std::string >;
134[[nodiscard]]
inline std::vector< FrontPair >
153[[nodiscard]]
inline std::vector< std::string >
201class FrontCodedDictionary
225 [[nodiscard]]
static FrontCodedDictionary
226 bucketed(
const std::vector< std::string > & D , std::size_t b );
254 [[nodiscard]]
static FrontCodedDictionary
272 [[nodiscard]] std::string
access( std::size_t i )
const;
307 [[nodiscard]] std::size_t
prefixEnd( std::string_view P )
const;
311 [[nodiscard]] std::pair< std::size_t , std::size_t >
337 [[nodiscard]] std::size_t
rankInBucket( std::size_t k , std::string_view P ,
341 [[nodiscard]] std::size_t
size(
void )
const;
344 [[nodiscard]] std::size_t
anchors(
void )
const;
348 [[nodiscard]] std::size_t
anchor( std::size_t k )
const;
358 [[nodiscard]] std::size_t
bytes(
void )
const;
381 : f_d( d ) , f_i( i ) {
401 return( f_i == o.f_i );
407 if( f_d && ( f_i < f_d->
size() ) ) {
408 f_s.resize( f_d->f_l[ f_i ] );
409 f_s.append( f_d->rest( f_i ) );
413 const FrontCodedDictionary * f_d =
nullptr;
450 [[nodiscard]] std::string_view rest( std::size_t i )
const;
453 [[nodiscard]] std::size_t anchorBefore( std::size_t i )
const;
456 [[nodiscard]] std::size_t anchorRank( std::string_view P ,
bool upper )
const;
458 std::vector< std::size_t > f_l;
459 std::vector< std::size_t > f_off;
461 std::vector< std::size_t > f_a;
462 std::size_t f_bytes = 0;
474#include "ADS/string/impl/FrontCoding.tpp"
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The search by prefix in a sorted dictionary of strings, beyond the book: the strings prefixed by ar...
a constant view of the strings in their order, decoded one after the other, forward; *it is the strin...
Definition FrontCoding.h:365
std::string value_type
a string
Definition FrontCoding.h:368
const_iterator(void)=default
an iterator on no dictionary
bool operator==(const const_iterator &o) const
whether the two iterators are at the same place
Definition FrontCoding.h:400
std::forward_iterator_tag iterator_concept
a forward iterator for the concepts
Definition FrontCoding.h:371
std::ptrdiff_t difference_type
a distance of iterators
Definition FrontCoding.h:369
const std::string & reference
the string decoded
Definition FrontCoding.h:367
const_iterator operator++(int)
the next string, this one returned
Definition FrontCoding.h:394
std::input_iterator_tag iterator_category
an input iterator for the algorithms of C++17, since *it is a reference into the iterator
Definition FrontCoding.h:374
const_iterator(const FrontCodedDictionary *d, std::size_t i)
the iterator on the string of *d, decoded from the string 0
Definition FrontCoding.h:380
const_iterator & operator++(void)
the next string, decoded from this one
Definition FrontCoding.h:388
reference operator*(void) const
the string decoded
Definition FrontCoding.h:386
a sorted dictionary of strings in the front coding, with anchors
Definition FrontCoding.h:202
std::string access(std::size_t i) const
the string , decoded from the anchor before it
std::size_t prefixEnd(std::string_view P) const
the number of strings smaller than
std::size_t lexicographicPosition(std::string_view Q) const
the number of strings smaller than
std::string value_type
a string
Definition FrontCoding.h:418
const_iterator iterator
the constant view
Definition FrontCoding.h:423
std::ptrdiff_t difference_type
a distance of places
Definition FrontCoding.h:420
const_iterator end(void) const
past the last string
Definition FrontCoding.h:430
std::size_t anchors(void) const
the number of anchors, the strings stored whole
const std::string & const_reference
a string decoded
Definition FrontCoding.h:422
const_iterator cbegin(void) const
the first string
Definition FrontCoding.h:434
std::size_t rankInBucket(std::size_t k, std::string_view P, bool upper) const
the number of strings smaller than (or if upper), given that anchors are: the scan of the bucket
static FrontCodedDictionary bucketed(const std::vector< std::string > &D, std::size_t b)
the front coding of with an anchor every strings
std::size_t decodeCost(std::size_t i) const
the characters that access( i ) reads, those of the rests from the anchor before to
const std::string & reference
a string decoded
Definition FrontCoding.h:421
static FrontCodedDictionary localityPreserving(const std::vector< std::string > &D, double c)
the locality-preserving front coding of , of parameter
std::size_t anchor(std::size_t k) const
the place in the dictionary of the anchor
std::string_view anchorString(std::size_t k) const
the string of the anchor
std::size_t size(void) const
the number of strings
std::size_t bytes(void) const
the bytes of the coding, the characters and the codes of the lengths
const_iterator begin(void) const
the first string
Definition FrontCoding.h:426
const_iterator cend(void) const
past the last string
Definition FrontCoding.h:436
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 size_type
a number of strings
Definition FrontCoding.h:419
std::size_t characters(void) const
the characters of the coding, those of the rests and of the anchors
void load(Ar &a, T &x)
the structure read from the archive of cereal
Definition Cereal.h:238
std::vector< FrontPair > frontCode(const std::vector< std::string > &D)
the front coding of , a pair per string
std::uint32_t decodeLength(std::string_view in, std::size_t &pos)
the length coded at in[ pos ], with pos moved past its code
void encodeLength(std::uint32_t l, std::string &out)
appends to out the code of in 1 to 4 bytes, the first two bits giving the number of bytes minus 1
std::vector< std::string > frontDecode(const std::vector< FrontPair > &F)
the strings of the front coding
std::pair< std::size_t, std::string > FrontPair
a pair of the front coding, the length of the prefix shared with the string before and the rest
Definition FrontCoding.h:117