我试图了解霍夫曼编码的工作原理。我读过的所有摘要都说明了如何生成值代码,但没有说明如何实际读取它们的完整过程。我想知道算法如何知道要读取的每个值的位长。 >
例如,如果您用代码系列“ 01-110-1101-1-10”表示符号字符串“ ETQ A”,您如何知道一个符号在哪里开始而另一符号在哪里结束?您怎么知道要读索引1的两位,索引2的三位,等等?
答案 0 :(得分:0)
解码时有两个给定值:
然后,您只消耗这些位,直到到达叶节点为止,此时您将终止该点以进行单字符解码。
decoding http://people.cs.pitt.edu/~kirk/cs1501/animations/Huffman/huff_dec.gif
然后您继续消耗比特直到所有字符都被解码
取自http://people.cs.pitt.edu/~kirk/cs1501/animations/Huffman.html
The decoding procedure is deceptively simple.
Starting with the first bit in the stream, one then uses successive bits from
the stream to determine whether
to go left or right in the decoding tree.
When we reach a leaf of the tree,
we've decoded a character, so we place
that character onto the (uncompressed)
output stream. The next bit in the
input stream is the first bit of the
next character.