ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
LempelZiv.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------------- File LempelZiv.h ----------------------------*/
3/*--------------------------------------------------------------------------*/
95/*--------------------------------------------------------------------------*/
96/*----------------------------- DEFINITIONS --------------------------------*/
97/*--------------------------------------------------------------------------*/
98
99#ifndef __ADS_LempelZiv
100 #define __ADS_LempelZiv
101/* self-identification: #endif constant */
102
103/*--------------------------------------------------------------------------*/
104/*------------------------------ INCLUDES ----------------------------------*/
105/*--------------------------------------------------------------------------*/
106
107#include "ADS/Contract.h"
108
109#include <algorithm>
110#include <cstddef>
111#include <cstdint>
112#include <limits>
113#include <map>
114#include <optional>
115#include <string>
116#include <string_view>
117#include <unordered_map>
118#include <utility>
119#include <vector>
120
121/*--------------------------------------------------------------------------*/
122/*--------------------------- NAMESPACE ------------------------------------*/
123/*--------------------------------------------------------------------------*/
124
125namespace ADS
126{
127
131{
132 std::size_t distance ,
134 std::optional< char > next;
136 friend bool operator==( const LZ77Phrase & a ,
137 const LZ77Phrase & b ) = default;
138 };
139
143{
144 std::size_t distance ,
146 char literal;
148 friend bool operator==( const LZSSPhrase & a ,
149 const LZSSPhrase & b ) = default;
150 };
151
154{
155 std::size_t id;
156 char next;
158 friend bool operator==( const LZ78Phrase & a ,
159 const LZ78Phrase & b ) = default;
160 };
161
191[[nodiscard]] inline std::vector< LZ77Phrase >
192lz77Parse( std::string_view s ,
193 std::size_t w = std::numeric_limits< std::size_t >::max() );
194
214[[nodiscard]] inline std::string
215lz77Decode( const std::vector< LZ77Phrase > & P );
216
239[[nodiscard]] inline std::vector< LZSSPhrase >
240lzssParse( std::string_view s ,
241 std::size_t w = std::numeric_limits< std::size_t >::max() ,
242 std::size_t minLength = 1 );
243
284[[nodiscard]] inline std::vector< LZSSPhrase > lzssParseHashed(
285 std::string_view s , std::size_t w , std::size_t minLength = 3 ,
286 std::size_t maxChain = std::numeric_limits< std::size_t >::max() );
287
305[[nodiscard]] inline std::string
306lzssDecode( const std::vector< LZSSPhrase > & P );
307
335[[nodiscard]] inline std::vector< LZ78Phrase > lz78Parse(
336 std::string_view s ,
337 std::size_t maxPhrases = std::numeric_limits< std::size_t >::max() );
338
357[[nodiscard]] inline std::string lz78Decode(
358 const std::vector< LZ78Phrase > & P ,
359 std::size_t maxPhrases = std::numeric_limits< std::size_t >::max() );
360
382[[nodiscard]] inline std::vector< std::uint32_t >
383lzwEncode( std::string_view s );
384
406[[nodiscard]] inline std::string
407lzwDecode( const std::vector< std::uint32_t > & I );
408
409/*--------------------------------------------------------------------------*/
410
411} // end( namespace ADS )
412
413/*--------------------------------------------------------------------------*/
414/*-------------------------- IMPLEMENTATION --------------------------------*/
415/*--------------------------------------------------------------------------*/
416
417#include "ADS/compression/impl/LempelZiv.tpp"
418
419/*--------------------------------------------------------------------------*/
420
421#endif /* LempelZiv.h included */
422
423/*--------------------------------------------------------------------------*/
424/*-------------------------- End File LempelZiv.h --------------------------*/
425/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
std::vector< LZSSPhrase > lzssParseHashed(std::string_view s, std::size_t w, std::size_t minLength=3, std::size_t maxChain=std::numeric_limits< std::size_t >::max())
the parse of LZSS of by the chains of the hashes of 3 symbols, as in gzip, following at most maxChai...
std::string lzwDecode(const std::vector< std::uint32_t > &I)
the text of the code of LZW
std::vector< std::uint32_t > lzwEncode(std::string_view s)
the identifiers of the code of LZW of
std::string lz77Decode(const std::vector< LZ77Phrase > &P)
the text of the phrases of LZ77
std::vector< LZ78Phrase > lz78Parse(std::string_view s, std::size_t maxPhrases=std::numeric_limits< std::size_t >::max())
the parse of LZ78 of , the dictionary restarting when it has maxPhrases phrases besides the empty one
std::string lzssDecode(const std::vector< LZSSPhrase > &P)
the text of the phrases of LZSS
std::vector< LZ77Phrase > lz77Parse(std::string_view s, std::size_t w=std::numeric_limits< std::size_t >::max())
the parse of LZ77 of with a window of symbols, the closest among the longest copies
std::string lz78Decode(const std::vector< LZ78Phrase > &P, std::size_t maxPhrases=std::numeric_limits< std::size_t >::max())
the text of the phrases of LZ78
std::vector< LZSSPhrase > lzssParse(std::string_view s, std::size_t w=std::numeric_limits< std::size_t >::max(), std::size_t minLength=1)
the parse of LZSS of with a window of symbols, a copy for the closest among the longest prefixes of...
Definition ADT.h:96
a phrase of LZ77: copy length symbols from distance back, then next (none at the end of the text); di...
Definition LempelZiv.h:131
friend bool operator==(const LZ77Phrase &a, const LZ77Phrase &b)=default
whether the two phrases are equal
std::size_t distance
how far back the copy starts
Definition LempelZiv.h:132
std::size_t length
the symbols copied
Definition LempelZiv.h:133
std::optional< char > next
the symbol after the copy, if any
Definition LempelZiv.h:134
a phrase of LZ78: the phrase id followed by next
Definition LempelZiv.h:154
std::size_t id
the phrase of the dictionary, 0 the empty one
Definition LempelZiv.h:155
friend bool operator==(const LZ78Phrase &a, const LZ78Phrase &b)=default
whether the two phrases are equal
char next
the symbol that follows it
Definition LempelZiv.h:156
a phrase of LZSS: a copy of length symbols from distance back, or the literal when distance is 0
Definition LempelZiv.h:143
char literal
the symbol of a literal
Definition LempelZiv.h:146
std::size_t distance
how far back the copy starts, 0 for a literal
Definition LempelZiv.h:144
friend bool operator==(const LZSSPhrase &a, const LZSSPhrase &b)=default
whether the two phrases are equal
std::size_t length
the symbols copied, 1 for a literal
Definition LempelZiv.h:145