Skip to main content

Module fsst

Module fsst 

Source
Expand description

FSST string compression (encoding id 8), the Boncz, Neumann and Leis static symbol table: up to 255 symbols of 1 to 8 bytes replace common substrings with one-byte codes, and code 255 escapes a literal byte. Decompression is a table lookup per code with no entropy coding, which is what lets it hit the 1 GB/s decode floor while still halving typical text; random access into a compressed segment only needs the 2 KiB table, not the whole block, which is why FullZip string segments will ride it.

The encoder trains on a sample with the iterative construction from the paper: parse the sample with the current table, credit each matched symbol and each concatenation of adjacent matches with the bytes it would save, and keep the highest earners for the next round. Operates on a flat byte buffer; string boundaries are structural (offsets live with the FullZip layout) and no symbol ever crosses a value boundary in practice because the training sample keeps them rare and correctness never depends on it.

Layout: raw_len: u32 LE, symbol_count: u8, one length byte per symbol (1 to 8), the concatenated symbol bytes, then the code stream.

Structs§

Table
A trained symbol table, separated from the encode pass because the two cost wildly different amounts: training a table for one 1024-row chunk of short strings runs about 3.4ms and encoding that chunk against it runs about 0.13ms, so a writer that trains per chunk spends 96% of its time in training. A writer holding a column of chunks that are alike trains once, on a sample drawn across the whole column, and encodes every chunk with the result. Nothing about the encoded form changes: each buffer still carries the table it was encoded with, so a decoder cannot tell which of the two a writer did.

Functions§

decode
Decodes an encoded buffer, appending at most max_bytes bytes to out. The claimed length, every symbol length, and every code are checked, and a rejected payload leaves out untouched. Scratch is the 255-entry padded table, well under the 64 KiB decoder ceiling.
encode
Trains a table on bytes and encodes bytes with it, returning the encoded byte length. Table is the form to reach for when more than one buffer is going to be encoded the same way.