My Project
 
Loading...
Searching...
No Matches
HuffmanEncoder Class Reference

Encodes data using Huffman coding and writes it to a file in binary format. More...

#include <HuffmanEncoder.hpp>

Collaboration diagram for HuffmanEncoder:
Collaboration graph

Public Member Functions

 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.
 

Private Member Functions

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.
 

Private Attributes

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 HuffmanTreetree
 Pointer to the Huffman tree used for encoding.
 

Detailed Description

Encodes data using Huffman coding and writes it to a file in binary format.

Constructor & Destructor Documentation

◆ HuffmanEncoder()

HuffmanEncoder::HuffmanEncoder ( const string & fn,
const HuffmanTree * root )

Constructs a HuffmanEncoder with output file and tree reference.

Parameters
fnOutput file name.
rootPointer to the Huffman tree.

Member Function Documentation

◆ encodeToFile() [1/2]

void HuffmanEncoder::encodeToFile ( const string & fn)

Encodes file contents (given by filename) and writes the encoded output.

Parameters
fnInput file name to be read and encoded.
Here is the call graph for this function:

◆ encodeToFile() [2/2]

void HuffmanEncoder::encodeToFile ( const vector< uint8_t > str)

Encodes a byte vector and writes it to the output file.

Parameters
strThe input data as a byte vector.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insertToBuffer()

void HuffmanEncoder::insertToBuffer ( const bitset< 32 > & code)
private

Inserts a 32-bit code into the internal buffer, managing space and alignment.

Parameters
codeThe bitset representing the Huffman code.
Here is the caller graph for this function:

◆ writeEncodedString()

void HuffmanEncoder::writeEncodedString ( )
private

Encodes the string using the Huffman tree and writes the resulting bitstream.

Here is the caller graph for this function:

◆ writeHeader()

void HuffmanEncoder::writeHeader ( )
private

Writes the header of the encoded file, including code map sizes and padding info.

Here is the caller graph for this function:

◆ writeMapToBinary()

void HuffmanEncoder::writeMapToBinary ( )
private

Serializes the Huffman code maps (8b/16b/32b) to the output file in binary format.

Here is the caller graph for this function:

Member Data Documentation

◆ 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

const HuffmanTree* HuffmanEncoder::tree
private

Pointer to the Huffman tree used for encoding.


The documentation for this class was generated from the following files: