在https://www.rfc-editor.org/rfc/rfc1951
Note that in the "deflate" format, the Huffman codes for the
various alphabets must not exceed certain maximum code lengths.
Run Code Online (Sandbox Code Playgroud)
最大代码长度定义为 15。
当霍夫曼码长度超过15时会发生什么?
来自https://cs.stackexchange.com/questions/75542/maximum-size-of-huffman-codes-for-an-alphabet-containing-256-letters 256 个符号字母表的最大可能代码大小是 256 位。考虑以下情况:最频繁的符号的频率为 1/2,下一个最频繁的符号的频率为 1/4,然后是 1/8
因此,在文字/长度字母表中,最大霍夫曼代码长度为 285-1=284,但在 zlib 中,最大代码长度为 15。