def _make_decode_tree(self, meta): """ meta : list, contains key at even index and decoding value at odd index. """ tree = binary() for x in xrange(0, len(meta) - 1, 2): temp = tree for decode in meta[x+1]: if decode == '1': if temp.right == None: temp.right = binary() temp = temp.right else: temp = temp.right elif decode == '0': if temp.left == None: temp.left = binary() temp = temp.left else: temp = temp.left temp.key = meta[x] return tree
def _make_tree(self): #Create single node trees in desceding order stored in list trees = [] for x in self.freq: trees.append(binary(value = x[1], key = x[0])) #return descending order list return trees[::-1]
def _merge(self, tree1, tree2): """Utility function to merge two trees into one input ===== tree1, tree2: binary_tree.Binary, binary tree object """ temp = binary() temp.value = tree1.value + tree2.value temp.left = tree1 temp.right = tree2 return temp