Module dsa.huffman
a collection of Huffman functions
Functions
def bitstring_to_bytes(s)def build_frequency_table(s: str)-
accepts a string to encode and returns a heap of the characters
def build_huffman_dictionary(node, bit_string: str = '')-
given a Huffman Node, build a Huffman Dictionary
def build_huffman_tree(heap)-
accepts a heap and returns a Huffman Tree
def bytes_to_bitstring(ba, bitlength=8)def character_frequency(s: str)-
takes a string a returns a dictionary on character frequency
def huffman_decode(encoded_data, tree)def huffman_encode(st, hd)
Classes
class Node (left, right, value=None)-
binary node implementation
Expand source code
class Node: """ binary node implementation """ def __init__(self, left, right, value=None): self.left = left self.right = right self.value = value def __lt__(self, other): return False def __repr__(self): if self.value is None: return "none" else: return self.value