diff --git a/ov8/HM_compression.py b/ov8/HM_compression.py index ccb3147ec3757eb886aa7cdef83384bfcf8853b9..2506d200b18c297ced243ce8280c64dd297473cd 100644 --- a/ov8/HM_compression.py +++ b/ov8/HM_compression.py @@ -49,22 +49,12 @@ for i in all_strings: table = sorted(table,key=lambda x: x.freq) -# A Huffman Tree Node class node: def __init__(self, freq, symbol, left=None, right=None): - # frequency of symbol self.freq = freq - - # symbol name (character) self.symbol = symbol - - # node left of current node self.left = left - - # node right of current node self.right = right - - # tree direction (0/1) self.huff = '' @@ -76,59 +66,38 @@ class rep_tree(): def printNodes(node, val=''): - # huffman code for current node newVal = val + str(node.huff) - # if node is not an edge node - # then traverse inside it if(node.left): printNodes(node.left, newVal) if(node.right): printNodes(node.right, newVal) - # if node is edge node then - # display its huffman code if(not node.left and not node.right): rep_tree_arr.append(rep_tree(node.symbol, newVal)) - - -# list containing unused nodes nodes = [] - for j in table: nodes.append(node(j.freq, j.char)) while len(nodes) > 1: - - # pick 2 smallest nodes left = nodes[0] right = nodes[1] - - # assign directional value to these nodes left.huff = 0 right.huff = 1 - - # combine the 2 smallest nodes to create - # new node as their parent newNode = node(left.freq+right.freq, left.symbol+right.symbol, left, right) - - # remove the 2 nodes and add their - # parent as new node among others nodes.remove(left) nodes.remove(right) nodes.append(newNode) -# Huffman Tree is ready! printNodes(nodes[0]) bit_string = '' - for i in all_strings: a = [a for a in rep_tree_arr if a.symb == i] bit_string += a[0].val diff --git a/ov8/HM_uncompression.py b/ov8/HM_uncompression.py index 4eeebcf4e71cac96ffea93b1e3c3d3784205f376..7cb1e4cba2ad92ccea937da41f3c63ab2b61652f 100644 --- a/ov8/HM_uncompression.py +++ b/ov8/HM_uncompression.py @@ -101,6 +101,7 @@ for i in range(0,len(lz_code),6): elif k not in string.printable: print('extende') counter +=1 + print(counter) with open('./hm_uncomp', 'a') as file: file.write(huff_string[:value-counter]) huff_string = huff_string[value-counter:] diff --git a/ov8/hm_uncomp b/ov8/hm_uncomp index 1cfe83f1d08f9bcbc6c8dce44dc3445c2ba2a659..6f681179d724e9a01a8cfcf37f85ba105e6dbae3 100644 Binary files a/ov8/hm_uncomp and b/ov8/hm_uncomp differ