在inftrees.c (从规范的huffman表示构造查找表的代码)中,作者写道:
/* 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虽然我读了很多次这个评论,但我还是能理解掉的意思是什么。另一个问题是作者使用什么方法来构建huffman代码?什么是反向增量?
你能给我解释一下吗,谢谢。
发布于 2011-12-18 17:42:59
“向后增量huff”的意思是huff = rev(rev(huff) + 1),其中rev反转位0, ..., len - 1。
假设len == 7和huff是二进制格式的1110100。我们寻找第一个清除位,清除所有较低的(意指)/higher(位模式),并设置该位。
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 += incrhttps://stackoverflow.com/questions/8553159
复制相似问题