【问题标题】:The zlib implementation of inflate algorithm膨胀算法的zlib实现
【发布时间】:2011-12-18 16:41:38
【问题描述】:

inftrees.c,这是从规范的霍夫曼表示构造查找表的代码,作者写道:

 /* replicate for those indices with low len bits equal to huff */
    incr = 1U << (len - drop);
    fill = 1U << curr;
    min = fill;                 /* save offset to next table */
    do {
        fill -= incr;
        next[(huff >> drop) + fill] = here;
    } while (fill != 0);

    /* backwards increment the len-bit code huff */
    incr = 1U << (len - 1);
    while (huff & incr)
        incr >>= 1;
    if (incr != 0) {
        huff &= incr - 1;
        huff += incr;
    }
    else
        huff = 0

虽然我多次阅读评论,但我可以弄清楚 drop 的含义是什么。另一个问题是作者使用什么方法来构建霍夫曼代码?什么是向后增量?

你能帮我解释一下吗,谢谢。

【问题讨论】:

    标签: algorithm deflate


    【解决方案1】:

    “向后递增huff”表示huff = rev(rev(huff) + 1),其中rev 反转位0, ..., len - 1

    假设len == 7huff 是二进制的1110100。我们寻找第一个清除位,清除所有较低(含义)/较高(位模式)的内容,然后设置该位。

    1110100
    ^
    1000000 == incr: loop continues
     ^
    0100000 == incr: loop continues
      ^
    0010000 == incr: loop continues
       ^
    0001000 == incr: loop breaks
    
    1110100: huff
    0000111: incr - 1
    0000100: huff &= (incr - 1)
    0001100: huff += incr
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      • 2014-07-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多