Encodes data using Huffman coding and writes it to a file in binary format.
More...
#include <HuffmanEncoder.hpp>
|
| HuffmanEncoder (const string &fn, const HuffmanTree *root) |
| Constructs a HuffmanEncoder with output file and tree reference.
|
|
void | encodeToFile (const vector< uint8_t > str) |
| Encodes a byte vector and writes it to the output file.
|
|
void | encodeToFile (const string &fn) |
| Encodes file contents (given by filename) and writes the encoded output.
|
|
|
void | writeHeader () |
| Writes the header of the encoded file, including code map sizes and padding info.
|
|
void | writeMapToBinary () |
| Serializes the Huffman code maps (8b/16b/32b) to the output file in binary format.
|
|
void | writeEncodedString () |
| Encodes the string using the Huffman tree and writes the resulting bitstream.
|
|
void | insertToBuffer (const bitset< 32 > &code) |
| Inserts a 32-bit code into the internal buffer, managing space and alignment.
|
|
|
vector< u_int32_t > | buffer |
| A buffer that stores 32-bit chunks of the encoded bitstream.
|
|
uint8_t | space_left |
| Indicates the remaining unused bits in the current buffer element.
|
|
ofstream | outFile |
| Output file stream to which encoded data is written.
|
|
const HuffmanTree * | tree |
| Pointer to the Huffman tree used for encoding.
|
|
Encodes data using Huffman coding and writes it to a file in binary format.
◆ HuffmanEncoder()
HuffmanEncoder::HuffmanEncoder |
( |
const string & | fn, |
|
|
const HuffmanTree * | root ) |
Constructs a HuffmanEncoder with output file and tree reference.
- Parameters
-
fn | Output file name. |
root | Pointer to the Huffman tree. |
◆ encodeToFile() [1/2]
void HuffmanEncoder::encodeToFile |
( |
const string & | fn | ) |
|
Encodes file contents (given by filename) and writes the encoded output.
- Parameters
-
fn | Input file name to be read and encoded. |
◆ encodeToFile() [2/2]
void HuffmanEncoder::encodeToFile |
( |
const vector< uint8_t > | str | ) |
|
Encodes a byte vector and writes it to the output file.
- Parameters
-
str | The input data as a byte vector. |
◆ insertToBuffer()
void HuffmanEncoder::insertToBuffer |
( |
const bitset< 32 > & | code | ) |
|
|
private |
Inserts a 32-bit code into the internal buffer, managing space and alignment.
- Parameters
-
code | The bitset representing the Huffman code. |
◆ writeEncodedString()
void HuffmanEncoder::writeEncodedString |
( |
| ) |
|
|
private |
Encodes the string using the Huffman tree and writes the resulting bitstream.
◆ writeHeader()
void HuffmanEncoder::writeHeader |
( |
| ) |
|
|
private |
Writes the header of the encoded file, including code map sizes and padding info.
◆ writeMapToBinary()
void HuffmanEncoder::writeMapToBinary |
( |
| ) |
|
|
private |
Serializes the Huffman code maps (8b/16b/32b) to the output file in binary format.
◆ buffer
vector<u_int32_t> HuffmanEncoder::buffer |
|
private |
A buffer that stores 32-bit chunks of the encoded bitstream.
◆ outFile
ofstream HuffmanEncoder::outFile |
|
private |
Output file stream to which encoded data is written.
◆ space_left
uint8_t HuffmanEncoder::space_left |
|
private |
Indicates the remaining unused bits in the current buffer element.
◆ tree
Pointer to the Huffman tree used for encoding.
The documentation for this class was generated from the following files: