Module for Huffman encoding and decoding.
This module provides classes for Huffman encoding and decoding. It uses the Pipe module for data transfer between different stages of the encoding and decoding process.
Here is an example of how to use this module to perform Huffman encoding and decoding:
#include <iostream>
#include <memory>
using namespace std;
using namespace Pipe;
using namespace Huffman;
int main() {
const char* input_data = "example data to compress";
size_t input_size = strlen(input_data);
auto pipe_mem_reader = make_shared<CMemReaderPipe>(reinterpret_cast<const u8*>(input_data), input_size);
auto pipe_mem_packed = make_shared<CMemBufferPipe>();
encoder.
SetIn(pipe_mem_reader);
encoder.
SetOut(pipe_mem_packed);
cout << "Encoded Data Dump:" << endl;
pipe_mem_packed->Dump();
auto decode_pipe_in = make_shared<CMemBufferPipe>();
auto decode_pipe_out = make_shared<CMemBufferPipe>();
Pipe::Move(pipe_mem_packed, decode_pipe_in);
decoder.
SetIn(decode_pipe_in);
decoder.
SetOut(decode_pipe_out);
if (decoder.
Decode() != CHuffmanDecoder::DECODE_OK) {
cerr << "Decoding failed!" << endl;
return 1;
}
cout << "Decoded Data Dump:" << endl;
decode_pipe_out->Dump();
return 0;
}
Class for Huffman decoding.
Definition huffman.h:161
void SetIn(std::shared_ptr< Pipe::CPipe > pipe_in_)
Sets the input pipe for the decoder.
Definition huffman.cpp:609
CHuffmanDecoder::DecodeResult Decode()
Performs Huffman decoding on the input data.
Definition huffman.cpp:540
void SetOut(std::shared_ptr< Pipe::CPipe > pipe_out_)
Sets the output pipe for the decoder.
Definition huffman.cpp:613
Class for Huffman encoding.
Definition huffman.h:129
void SetIn(std::shared_ptr< Pipe::CPipe > pipe_in_)
Sets the input pipe for the encoder.
Definition huffman.cpp:342
void SetOut(std::shared_ptr< Pipe::CPipe > pipe_out_)
Sets the output pipe for the encoder.
Definition huffman.cpp:346
void Encode()
Performs Huffman encoding on the input data.
Definition huffman.cpp:357
Module for Huffman encoding and decoding.
Module for data pipeline processing using pipes.