LZSS compression of a block of data on its own, with a preset dictionary: text that both ends hold, which the block may copy from as if it came just before the block.
More...
|
| | Lzss (const uint8_t *dictionary, size_t dictionary_size) |
| |
| size_t | dictionary_size () const |
| |
| size_t | compress (const uint8_t *in, size_t size, uint8_t *out, size_t capacity, uint16_t *chains) const |
| | Compress size bytes into out, which holds capacity bytes, using chains (CHAIN_WORDS words) as working space; returns the length, or 0 if it does not fit.
|
| |
| size_t | expand (const uint8_t *in, size_t size, uint8_t *out, size_t capacity) const |
| | Expand size bytes into out, which holds capacity bytes; returns the length, or SIZE_MAX if the data is malformed or expands to more than capacity.
|
| |
|
| static constexpr uint8_t | HASH_BITS = 8 |
| | The compressor finds earlier positions starting with the same two bytes through a hash table of this many bits.
|
| |
| static constexpr size_t | MAX_CHAIN = 32 |
| | How many earlier positions the compressor tries for each match; more finds longer matches, but takes longer.
|
| |
| static constexpr size_t | WINDOW = 512 |
| | Part of the format: a match reaches back at most this far, and offsets take the bits that the bytes behind the current position need, counting at most this many; a power of 2.
|
| |
| static constexpr size_t | MAX_MATCH = 65536 |
| | The longest match, as the decoder reads a length code of at most 16 bits after the first.
|
| |
| static constexpr size_t | CHAIN_WORDS = (size_t{1} << HASH_BITS) + WINDOW |
| | The working space compress() needs: the latest position for each hash, then the previous one for each position in the window.
|
| |
LZSS compression of a block of data on its own, with a preset dictionary: text that both ends hold, which the block may copy from as if it came just before the block.
Short blocks gain most from a dictionary that looks like them.
The compressed data is a stream of bits, the first in bit 7 of each byte:
- a 1 bit and 8 bits of a byte to copy;
- a 0 bit, an offset back from the current position, and a length from 2 to MAX_MATCH. The offset less 1 takes as many bits as the number of bytes behind the current position, counting the dictionary but at most WINDOW, less 1 needs, so near the start of a block it takes few bits. The length less 1 is an Elias gamma code: one 0 bit for each bit after the first, then the value. The last byte is padded with 1 bits, which read as the start of a byte to copy with too few bits left.
Definition at line 21 of file lzss.h.