This is a C++ project that demonstrates data compression and decompression using the Huffman coding algorithm. Huffman coding is a widely used method for lossless data compression, often utilized in file compression tools, data transmission, and various applications where efficient data storage is essential.
- Data Compression: Compresses text data using Huffman coding, resulting in a shorter binary representation.
- Data Decompression: Decompresses data that has been previously compressed using the Huffman algorithm.
- File Input/Output: Allows you to compress and decompress text data stored in files.
- Huffman Tree Generation: Builds Huffman trees based on the frequency of characters in the input data.
- Huffman Codes: Generates Huffman codes for each character in the input data.
- Command-Line Interface: Provides a simple command-line interface for compressing and decompressing files.
- C++: The project is written in C++ to implement the Huffman coding algorithm and handle file input/output.
- CMake: CMake is used for building the project.
- GitHub: The project is hosted on GitHub for version control.
Follow the steps below to use and build the project:
-
Clone the repository:
git clone https://github.com/ragab2010/huffman-coding.git
-
Build the project using CMake:
mkdir build cd build cmake .. make
-
Run the executable:
-
For compression:
./bin/MyHuffmanProject
-
For decompression:
./bin/MyHuffmanProject
-
- Compress Data: Use the program to compress text data and generate compressed files.
- Decompress Data: Use the program to decompress previously compressed files.
- Customization: You can modify the code to suit your specific needs, such as customizing compression/decompression behavior.
-
To compress a file:
./bin/MyHuffmanProject
-
To decompress a file:
./bin/MyHuffmanProject
1-get the string from the Txt file.
2-calculate the frequency of every character by using unordered_map.
3-build the Huffman Tree.
4-generate the Huffman tree header.
5-generate from the Huffman tree header the string of compressed code.
6-generate the compressed bin file and write on it the Huffman tree header + compressed code.
1-get the string from the bin file and the Huffman tree header.
2-rebuild the Huffman Tree.
4-get the characters from the Huffman Tree, to build the decompressed.
5-write the decompressed file with the original text.