【问题标题】:in zlib what happen when the Huffman code lengths for the alphabets exceed maximum code length(15)?在 zlib 中,当字母的霍夫曼代码长度超过最大代码长度(15)时会发生什么?
【发布时间】:2019-07-15 09:14:20
【问题描述】:

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.

最大代码长度定义为 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。

  1. 为什么选择 15 作为最大代码长度?
  2. 如果代码长度超过 15,zlib 会失败吗?

【问题讨论】:

    标签: zlib huffman-code


    【解决方案1】:
    1. 我们不确定 Phil Katz 选择 15 的原因,但它可能有助于在 16 位处理器中快速实现。

    2. 不,zlib 不会失败。它一直在发生。 zlib 实现应用了正常的 Huffman 算法,之后如果最长代码超过 15 位,则继续执行modify the codes to force them all to 15 bits or less

    请注意,生成 256 位长代码的示例需要一组 2256 ~= 1077 个符号才能达到这些频率。我认为你没有足够的内存。

    在任何情况下,zlib 通常将 deflate 块限制为 16384 个符号。对于该数字,最大霍夫曼代码长度为 19。这来自概率的斐波那契序列,而不是您的 2 次方。 (留给读者作为练习。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      相关资源
      最近更新 更多