compression.huffman

Classes

Letter

TreeNode

Functions

build_tree(→ Letter | TreeNode)

Run through the list of Letters and build the min heap

huffman(→ None)

Parse the file, build the tree, then run through the file

parse_file(→ list[Letter])

Read the file and build a dict of all letters and their

traverse_tree(→ list[Letter])

Recursively traverse the Huffman Tree to set each

Module Contents

class compression.huffman.Letter(letter: str, freq: int)
__repr__() str
bitstring: dict[str, str]
freq: int
letter: str
class compression.huffman.TreeNode(freq: int, left: Letter | TreeNode, right: Letter | TreeNode)
freq: int
left: Letter | TreeNode
right: Letter | TreeNode
compression.huffman.build_tree(letters: list[Letter]) Letter | TreeNode

Run through the list of Letters and build the min heap for the Huffman Tree.

compression.huffman.huffman(file_path: str) None

Parse the file, build the tree, then run through the file again, using the letters dictionary to find and print out the bitstring for each letter.

compression.huffman.parse_file(file_path: str) list[Letter]

Read the file and build a dict of all letters and their frequencies, then convert the dict into a list of Letters.

compression.huffman.traverse_tree(root: Letter | TreeNode, bitstring: str) list[Letter]

Recursively traverse the Huffman Tree to set each Letter’s bitstring dictionary, and return the list of Letters