ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
BurrowsWheeler.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------- File BurrowsWheeler.h --------------------------*/
3/*--------------------------------------------------------------------------*/
87/*--------------------------------------------------------------------------*/
88/*----------------------------- DEFINITIONS --------------------------------*/
89/*--------------------------------------------------------------------------*/
90
91#ifndef __ADS_BurrowsWheeler
92 #define __ADS_BurrowsWheeler
93/* self-identification: #endif constant */
94
95/*--------------------------------------------------------------------------*/
96/*------------------------------ INCLUDES ----------------------------------*/
97/*--------------------------------------------------------------------------*/
98
99#include "ADS/Contract.h"
104
105#include <algorithm>
106#include <bit>
107#include <cstddef>
108#include <cstdint>
109#include <map>
110#include <numeric>
111#include <span>
112#include <string>
113#include <string_view>
114#include <utility>
115#include <vector>
116
117/*--------------------------------------------------------------------------*/
118/*--------------------------- NAMESPACE ------------------------------------*/
119/*--------------------------------------------------------------------------*/
120
121namespace ADS
122{
123
126struct BWT
127{
128 std::string last;
129 std::size_t primary;
131 friend bool operator==( const BWT & a , const BWT & b ) = default;
132 };
133
154inline constexpr std::size_t bwtWideFrom = ( std::size_t( 1 ) << 31 ) - 1;
155
161[[nodiscard]] inline BWT bwt( std::string_view s ,
162 std::size_t wideFrom = bwtWideFrom );
163
183[[nodiscard]] inline std::vector< std::size_t > lfMapping( const BWT & b );
184
201[[nodiscard]] inline std::string inverseBwt( const BWT & b );
202
222[[nodiscard]] inline std::vector< std::uint8_t >
223moveToFront( std::string_view s , std::string_view alphabet );
224
235[[nodiscard]] inline std::vector< std::uint8_t >
236moveToFront( std::string_view s );
237
254[[nodiscard]] inline std::string
255inverseMoveToFront( const std::vector< std::uint8_t > & x ,
256 std::string_view alphabet );
257
268[[nodiscard]] inline std::string
269inverseMoveToFront( const std::vector< std::uint8_t > & x );
270
288[[nodiscard]] inline std::vector< std::pair< std::size_t , char > >
289runLengthEncode( std::string_view s );
290
304[[nodiscard]] inline std::string
305runLengthDecode( const std::vector< std::pair< std::size_t , char > > & R );
306
331[[nodiscard]] inline std::vector< std::uint32_t >
332zeroRunEncode( const std::vector< std::uint8_t > & x );
333
354[[nodiscard]] inline std::vector< std::uint8_t >
355zeroRunDecode( const std::vector< std::uint32_t > & y );
356
380[[nodiscard]] inline std::vector< std::uint8_t >
381bzipCompress( std::string_view s , std::size_t block = 900000 );
382
402[[nodiscard]] inline std::string
403bzipDecompress( std::span< const std::uint8_t > code );
404
405/*--------------------------------------------------------------------------*/
406
407} // end( namespace ADS )
408
409/*--------------------------------------------------------------------------*/
410/*-------------------------- IMPLEMENTATION --------------------------------*/
411/*--------------------------------------------------------------------------*/
412
413#include "ADS/compression/impl/BurrowsWheeler.tpp"
414
415/*--------------------------------------------------------------------------*/
416
417#endif /* BurrowsWheeler.h included */
418
419/*--------------------------------------------------------------------------*/
420/*----------------------- End File BurrowsWheeler.h ------------------------*/
421/*--------------------------------------------------------------------------*/
The canonical code of Huffman (chapter 12, Statistical Coding, of Ferragina's book): the lengths of ...
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The bits of the compressors of this folder, packed in bytes, since their input and their output are s...
The suffix array of a text of symbols, beyond the book: is the starting place of the -th smallest ...
The engineered construction of the suffix array and of its LCP array, beyond the book: the ones that ...
std::vector< std::size_t > lfMapping(const BWT &b)
the LF-mapping of the rows of the transform
BWT bwt(std::string_view s, std::size_t wideFrom=bwtWideFrom)
std::string inverseBwt(const BWT &b)
the text of the transform
std::string bzipDecompress(std::span< const std::uint8_t > code)
the text of a bzip
std::vector< std::uint32_t > zeroRunEncode(const std::vector< std::uint8_t > &x)
the RLE0 of bzip: the integers of but 0 grown by 1, each run of zeros in the code of Wheeler,...
std::string inverseMoveToFront(const std::vector< std::uint8_t > &x, std::string_view alphabet)
the symbols of the places in the list alphabet
std::vector< std::uint8_t > moveToFront(std::string_view s, std::string_view alphabet)
the places of the symbols of in the list alphabet, each moved to the front after its use
std::vector< std::uint8_t > bzipCompress(std::string_view s, std::size_t block=900000)
the bzip of : blocks of at most block symbols, each transformed, moved to front, coded by RLE0 and by...
constexpr std::size_t bwtWideFrom
the transform of
Definition BurrowsWheeler.h:154
std::vector< std::uint8_t > zeroRunDecode(const std::vector< std::uint32_t > &y)
the integers of an RLE0
std::vector< std::pair< std::size_t, char > > runLengthEncode(std::string_view s)
the maximal runs of as pairs of a length and a symbol
std::string runLengthDecode(const std::vector< std::pair< std::size_t, char > > &R)
the text of the runs
Definition ADT.h:96
the transform of Burrows and Wheeler: the last column of without the , and the row of the
Definition BurrowsWheeler.h:127
std::size_t primary
the row of the in
Definition BurrowsWheeler.h:129
friend bool operator==(const BWT &a, const BWT &b)=default
whether the two transforms have the same column and row
std::string last
the last column without the
Definition BurrowsWheeler.h:128