【发布时间】:2013-09-05 04:59:13
【问题描述】:
我想编写一个解压缩器,用于使用固定的 Huffman 代码对压缩数据进行压缩。 形成规范:
BTYPE specifies how the data are compressed, as follows: 00 - no compression 01 - compressed with fixed Huffman codes 10 - compressed with dynamic Huffman codes 11 - reserved (error) The only difference between the two compressed cases is how the Huffman codes for the literal/length and distance alphabets are defined.
我希望解压器在 BTYPE=01 时解压数据 我知道我必须首先解码霍夫曼代码,然后解压缩 lz77 但是当 BTYPE=01 时,霍夫曼树不与压缩数据一起存储
那么我如何在没有树的情况下解码 Huffman 代码?
已编辑:
所以霍夫曼代码将是这样的:
0 110000
1 110001
2 110010
144 110010000
145 110010001
255 111111111
256 0
257 1
258 10
259 11
260 100
279 10111
280 11000000
287 11000111
我不明白的是,如果我遇到代码 10,我如何区分距离代码中的值 2 和值 258 因为值 0-23 和 256-297 具有相同的代码
【问题讨论】:
-
不,霍夫曼代码不会是这样的。长度/文字的代码长度均为 7、8 或 9 位。看我的回答。
标签: compression huffman-code deflate