[英]How to decompress a huffman encoded file?
So once I have built my huffman tree and compressed a file into each characters' corresponding code how do I go about decompressing the file?因此,一旦我构建了我的霍夫曼树并将文件压缩到每个字符的相应代码中,我如何 go 关于解压缩文件? In the compressed file I have to insert some sort of information representing the huffman tree built in order to decompress the file.
在压缩文件中,我必须插入某种信息,表示为解压缩文件而构建的霍夫曼树。 I was initially thinking of storing the character with its' value for example:
我最初想用它的值来存储角色,例如:
a: 110 and b:11 for example. a:例如 110 和 b:11。 However, when reading the compressed file how would I differentiate the a from the b if both the a and b start with 11?
但是,在读取压缩文件时,如果 a 和 b 都以 11 开头,我将如何区分 a 和 b?
I don't feel like my method will work, does anyone have any better ideas?我觉得我的方法行不通,有没有人有更好的想法?
You're misunderstanding about huffman encoding.您对霍夫曼编码有误解。 Any character code in Huffman encoded code table must not be a prefix of other characters.
霍夫曼编码码表中的任何字符码都不能是其他字符的前缀。 If 'a' in your code is 110, 'b' must never starts with 1, 11 or 110. Each of character must not share their prefix.
如果代码中的“a”为 110,则“b”不得以 1、11 或 110 开头。每个字符不得共享其前缀。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.