Handles the complete lifecycle of Huffman encoding and decoding.
More...
#include <Huffman.h>
Handles the complete lifecycle of Huffman encoding and decoding.
◆ buildHuffmanTree()
| Node * Huffman::buildHuffmanTree |
( |
const uint64_t | histogram[ALPHABET_SIZE] | ) |
|
Builds the optimal Huffman tree using a priority queue.
- Parameters
-
| histogram | The pre-computed array of character frequencies. |
- Returns
- Pointer to the root node of the generated Huffman tree.
◆ compressFile()
| void Huffman::compressFile |
( |
const std::string & | inputFilePath, |
|
|
const std::string & | outputFilePath ) |
Compresses an input file using Huffman encoding.
- Parameters
-
| inputFilePath | Path to the original file to compress. |
| outputFilePath | Path where the compressed binary file (.huff) will be saved. |
◆ computeHistogram()
| void Huffman::computeHistogram |
( |
const std::string & | inputFilePath, |
|
|
uint64_t | histogram[ALPHABET_SIZE] ) |
Computes the frequency of each byte in the input file.
- Parameters
-
| inputFilePath | Path to the file to be analyzed. |
| histogram | Array of size ALPHABET_SIZE where frequencies will be stored. |
◆ decompressFile()
| void Huffman::decompressFile |
( |
const std::string & | inputFilePath, |
|
|
const std::string & | outputFilePath ) |
Decompresses a Huffman encoded file back to its original state.
- Parameters
-
| inputFilePath | Path to the compressed file (.huff). |
| outputFilePath | Path where the restored data will be written (or /dev/stdout). |
◆ generateCodeTable()
| void Huffman::generateCodeTable |
( |
Node * | root, |
|
|
Code & | currentNode, |
|
|
Code | codeTable[ALPHABET_SIZE] ) |
Generates the binary codes for all characters by traversing the tree.
- Parameters
-
| root | Pointer to the root of the Huffman tree. |
| currentNode | A temporary Code object used during traversal (must be empty initially). |
| codeTable | Array where the resulting codes will be stored, indexed by character. |
◆ reconstructTree()
| Node * Huffman::reconstructTree |
( |
const uint8_t | tree_dump[], |
|
|
uint32_t | dump_size ) |
Rebuilds a Huffman tree from its serialized post-order dump.
- Parameters
-
| tree_dump | Array containing the 'L' (Leaf) and 'T' (Interior) byte sequence. |
| dump_size | The length of the tree_dump array. |
- Returns
- Pointer to the root of the reconstructed Huffman tree.
◆ writeTreeDump()
| void Huffman::writeTreeDump |
( |
Node * | root, |
|
|
std::ofstream & | outFile ) |
Serializes the Huffman tree to a file using post-order traversal.
- Parameters
-
| root | Pointer to the root of the tree to be dumped. |
| outFile | The output file stream where the tree will be written. |
The documentation for this class was generated from the following files: