@@ -58,7 +58,7 @@ class SimpleCompression:
5858
5959 def uncompress (self , bits ):
6060 string = ' '
61- for i in xrange (0 , len (bits), self .bit_len):
61+ for i in range (0 , len (bits), self .bit_len):
6262 string += self .b2s[bits[i:i + self .bit_len]]
6363 return string
6464
@@ -71,8 +71,14 @@ class HuffmanCompression:
7171 self .coding = ' '
7272 self .left = self .right = None
7373
74- def __cmp__ (self , other ):
75- return self .val - other.val
74+ def __eq__ (self , other ):
75+ return self .val == other.val
76+
77+ def __lt__ (self , other ):
78+ return self .val < other.val
79+
80+ def __gt__ (self , other ):
81+ return self .val > other.val
7682
7783 def __init__ (self , string ):
7884 self .string = string
@@ -169,6 +175,4 @@ Huffman Compression-compress rate: 45%
169175简单压缩: 根据字符串出现的字符,将ASCII替换成更短的表示形式
170176霍夫曼压缩: 根据字符串出现频率,构建Trie树, 对每个tree node进行定义,使得频率越高的字符离root节点越近
171177
172-
173-
174178有关霍夫曼编码的具体步骤可参考 [ Huffman 编码压缩算法 | 酷 壳 - CoolShell.cn] ( http://coolshell.cn/articles/7459.html ) 和 [ 霍夫曼编码 - 维基百科,自由的百科全书] ( http://zh.wikipedia.org/wiki/%E9%9C%8D%E5%A4%AB%E6%9B%BC%E7%BC%96%E7%A0%81 ) ,清晰易懂。
0 commit comments