|
ADS
Algorithms and Data Structures
|
The code of Huffman of a string of bytes as the fast coders do it, beyond the canonical code of chapter 12, Statistical Coding, of Ferragina's book [see CanonicalHuffman.h], which decodes a bit at a time on a map of the symbols: More...
#include "ADS/Contract.h"#include <algorithm>#include <array>#include <bit>#include <cstddef>#include <cstdint>#include <cstring>#include <span>#include <vector>#include "ADS/compression/impl/HuffmanCoder.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Functions | |
| std::vector< std::uint8_t > | ADS::huffmanCompress (std::span< const std::uint8_t > in) |
| the code of Huffman of the bytes of in, with the lengths and the size | |
| std::vector< std::uint8_t > | ADS::huffmanDecompress (std::span< const std::uint8_t > in) |
| the bytes that huffmanCompress() coded in in | |
| std::array< std::uint8_t, 256 > | ADS::limitedHuffmanLengths (const std::array< std::uint64_t, 256 > &f, int L) |
| the optimal lengths of at most \( L \) bits of the codes of the 256 bytes of frequencies \( f \), 0 for a byte of frequency 0, by package-merge | |
The code of Huffman of a string of bytes as the fast coders do it, beyond the canonical code of chapter 12, Statistical Coding, of Ferragina's book [see CanonicalHuffman.h], which decodes a bit at a time on a map of the symbols:
These are the decoders by tables of Moffat and Turpin, with the interleaved streams of Zstandard; the speed comes from the table and from the streams, the size of the code is that of Huffman, within one bit per byte of the entropy, \( H_0 \le \bar\ell < H_0 + 1 \) [see Entropy.h] (the limit of 11 bits costs a fraction of a percent on a text of bytes, the optimum under it being found exactly). A string of one distinct byte is written as that byte.
The format: the size \( n \) in 8 bytes, the longest length (0 for one distinct byte, which follows), the 128 bytes of the lengths, the sizes of the first three streams in 4 bytes each, the four streams, and 8 bytes of 0 that let a decoder load a word anywhere in its stream; the integers are little-endian.
The contracts [see Contract.h]: huffmanDecompress() gets the output of huffmanCompress(), whose header (the lengths satisfy the inequality of Kraft, the sizes of the streams fit in the input) it checks; the audit of huffmanCompress() is that the output decompresses to the input. The functions are defined in HuffmanCoder.tpp.