nx_zstd_huf.nx
buildroot/runtime/nx_zstd_huf.nx
about
nx_zstd_huf.nx -- Zstandard's Huffman decode table (the X1 flat form).
The literals section's engine. zstd does not walk a Huffman tree bit by bit;
it builds a FLAT table of 2^tableLog entries where each symbol occupies a
contiguous run, peeks tableLog bits to index it in one step, then consumes
only the code's true length. That is why the reader needs peek and skip as
separate operations.
SLOT COUNT IS DRIVEN BY WEIGHT, NOT LENGTH. A symbol of weight w occupies
2^(w-1) slots, which is the same as 2^(tableLog - length) since
length = tableLog + 1 - w. Both forms appear in the literature and they are
equal only when the table log is right -- so a table built with the wrong
log fills a plausible number of slots and still fails to tile the table.
The build REFUSES unless the slots sum to exactly 2^tableLog.
RANKS ARE LAID OUT BY DESCENDING WEIGHT. Heaviest symbols (shortest codes)
take the lowest table indices. Laying them out in symbol order instead
produces a table that decodes self-consistently and disagrees with every
other zstd implementation -- the failure mode is a file that only this
decoder can read.
genealogy_id: zstandard_rfc8878_huffman
lineage_id: nx_zstd_huf_v1
license_tier: ORIGINAL
dependencies 2 imports · 5 importers
imports: nx_syscalls.nxnx_zstd_bits.nx
imported by: nx_zstd_block.nxnx_zstd_block_gate.nxnx_zstd_huf_gate.nxnx_zstd_lit.nxnx_zstd_lit_gate.nx
structs
| 33 | struct NxZstdHuf |
consts
| 29 | const NX_HUF_MAX_LOG: i64 = 12 |
| 30 | const NX_HUF_MAX_SYMBOLS: i64 = 256 |
| 31 | const NX_HUF_TBL_BYTES: i64 = 40 |
functions
| 47 | func nx_zstd_huf_build(weights: *i64, count: i64, table_log: i64) -> *NxZstdHuf |
| 131 | func nx_zstd_huf_symbol_at(t: *NxZstdHuf, idx: i64) -> i64 |
| 139 | func nx_zstd_huf_nbits_at(t: *NxZstdHuf, idx: i64) -> i64 |
| 151 | func nx_zstd_huf_decode(t: *NxZstdHuf, b: *NxZstdBits) -> i64 |