• 全部
  • 问答

Huffman编码的理解问题

Pollywog1983 2004-08-18 09:08:04
看Huffman编码的介绍文档,其中有一段不是很理解(第二段和第三段):
Huffman code decoding is performed using a multi-level table lookup.
The fastest way to decode is to simply build a lookup table whose
size is determined by the longest code. However, the time it takes
to build this table can also be a factor if the data being decoded
is not very long. The most common codes are necessarily the
shortest codes, so those codes dominate the decoding time, and hence
the speed. The idea is you can have a shorter table that decodes the
shorter, more probable codes, and then point to subsidiary tables for
the longer codes. The time it costs to decode the longer codes is
then traded against the time it takes to make longer tables.

This results of this trade are in the variables lbits and dbits
below. lbits is the number of bits the first level table for literal/
length codes can decode in one step, and dbits is the same thing for
the distance codes. Subsequent tables are also less than or equal to
those sizes. These values may be adjusted either when all of the
codes are shorter than that, in which case the longest code length in
bits is used, or when the shortest code is *longer* than the requested
table size, in which case the length of the shortest code in bits is
used.

There are two different values for the two tables, since they code a
different number of possibilities each. The literal/length table
codes 286 possible values, or in a flat code, a little over eight
bits. The distance table codes 30 possible values, or a little less
than five bits, flat. The optimum values for speed end up being
about one bit more than those, so lbits is 8+1 and dbits is 5+1.
The optimum values may differ though from machine to machine, and
possibly even between compilers. Your mileage may vary.
...全文
135 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
Pollywog1983 2004-08-19
在建立Huffman树函数的代码中,还有一段:
Return zero on success, one if the given code set is incomplete (the tables are still built in this case), two if the input is invalid (all zero length codes or an oversubscribed set of lengths), and three if not enough memory.
前面说执行成功返回0,但是后面给出的三种可能性却都是错误的状态,为什么会这样呢?
回复
Pollywog1983 2004-08-19
主要是第二段不是很理解,尤其是:“lbits is the number of bits the first level table for literal/length codes can decode in one step, and dbits is the same thing for
the distance codes.”.其中的“the first level table”是指什么?请指教!
回复
jp1984 2004-08-19
it is pretty easy when you program this thoery to code ,but it is a hard thing when refering to mathematical proof...being a beginner ,forget all the mathematical symbols ,code it...
回复
programfanny 2004-08-19
up to wait...
回复
Pollywog1983 2004-08-19
如果“the first level table”是指“shorter table”的话,那下面这一段又是什么意思呢:
These values may be adjusted either when all of the codes are shorter than that, in which case the longest code length in bits is used, or when the shortest code is *longer* than the requested table size, in which case the length of the shortest code in bits is used.
回复
zzwu 2004-08-19
第一段的第一句就说要采用多个level的 lookup table:

"Huffman code decoding is performed using a multi-level table lookup."

而其后说了一大堆使用单个表的坏话,排除了 "simply build a lookup table " (简单地使用一个表),

然后接着就提出了2个 lookup table ,一个 for shorter code, 另一个 for longer code,

这里虽没有明确说 shorter code 是“first level table”, for longer code 的是“second level table”, 但在上下文中不再有其他的table了.










回复
Pollywog1983 2004-08-19
谢谢!我现在知道了,原来是我理解错误了。我一直认为“one”是指返回值为0的一种的可能性。但是“the first level table”从我的理解来看应该不是“shorter table”,不过具体是指什么我还是不知道。
回复
zzwu 2004-08-19
Huffman编码函数的Return值:
0 - 成功
1 - 代码未完
2 - 输入无效
3 - 内存不够
回复
zzwu 2004-08-19
“the first level table”看来就是第一段中所说的 "shorter table".
回复
相关推荐
发帖
数据结构与算法
创建于2007-08-27

3.2w+

社区成员

数据结构与算法相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2004-08-18 09:08
社区公告
暂无公告