# 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.
...全文
138 点赞 收藏 9

9 条回复

Pollywog1983 2004-08-19

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.

Pollywog1983 2004-08-19

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...

Pollywog1983 2004-08-19

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

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

Pollywog1983 2004-08-19

zzwu 2004-08-19
Huffman编码函数的Return值:
0 - 成功
1 - 代码未完
2 - 输入无效
3 - 内存不够

zzwu 2004-08-19
“the first level table”看来就是第一段中所说的 "shorter table".

3.2w+