compression.huffman =================== .. py:module:: compression.huffman Classes ------- .. autoapisummary:: compression.huffman.Letter compression.huffman.TreeNode Functions --------- .. autoapisummary:: compression.huffman.build_tree compression.huffman.huffman compression.huffman.parse_file compression.huffman.traverse_tree Module Contents --------------- .. py:class:: Letter(letter: str, freq: int) .. py:method:: __repr__() -> str .. py:attribute:: bitstring :type: dict[str, str] .. py:attribute:: freq :type: int .. py:attribute:: letter :type: str .. py:class:: TreeNode(freq: int, left: Letter | TreeNode, right: Letter | TreeNode) .. py:attribute:: freq :type: int .. py:attribute:: left :type: Letter | TreeNode .. py:attribute:: right :type: Letter | TreeNode .. py:function:: build_tree(letters: list[Letter]) -> Letter | TreeNode Run through the list of Letters and build the min heap for the Huffman Tree. .. py:function:: 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. .. py:function:: 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. .. py:function:: 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