A C++ library that implements Huffman algorithm for text compression and decompression. Exclusive for text files.
This project was made as a part of my sophomore year 1st semester final project in Data Structures and Algorithms. The project initially consisted of monolith functions that was later converted to a library.
Profiling result shows sub 1000ms processing speed for up to 10 million characters.
The Huffman text compression algorithm employed by this library aims to achieve significant reduction in file size while maintaining lossless data compression. While the actual compression ratio may vary depending on factors such as the content and structure of the input text files, tests have shown that the compression ratio can reach up to 50%.
To use this library in your C++ project, follow these steps:
- Clone the repository or download the source code.
- Include the necessary files in your project. Make sure that the header file is in the appropriate folder location.
- Use the provided functions for compression and decompression.
bool huffmanlib::compress(string& filename): <filename>.compressed.huffman
Takes a string filename
as a parameter. Returns true if the compression is successful.
Assumes that the filename has .txt
file extension omitted. For example, if the file name is sample.txt
, the input should be sample
.
Appends .compressed.huffman
file extension to the compressed file.
bool huffmanlib::decompress(string& filename): <filename>.decompressed.txt
Takes a string filename
as a parameter. Returns true if the decompression is successful.
Assumes that the filename has .huffman
file extension omitted. For example, if the file name is sample.txt.compressed.huffman
, the input should be sample.txt.compressed
.
Appends .decompressed.txt
file extension to the decompressed file.
#include <iostream>
#include "huffmanlib.h" // Import the library
using namespace std;
using namespace huffmanlib;
int main() {
// Compress a text file
compress("input");
// Decompress a compressed file
decompress("compressed");
return 0;
}
📝 What is Huffman Encoding?.
This project is licensed under the MIT License.