A small C++ project that implements Huffman coding to compress and decompress data.
Huffman coding is a lossless compression technique that assigns shorter bit-codes to more frequent symbols and longer bit-codes to less frequent symbols, using a binary tree (the Huffman tree).
- A basic Huffman encoder/decoder implementation in C++
- Code that uses standard C++ features (including smart pointers) to build and traverse the Huffman tree
- Count frequency of each symbol in the input
- Build a Huffman tree using a priority queue (min-heap)
- Generate prefix-free binary codes by traversing the tree
- Encode the input into a bitstream using the generated codes
- Decode by walking the tree according to bits
This repository is intentionally lightweight and should compile with a standard g++ toolchain.
g++ -std=c++17 -O2 *.cpp -o huffmanIf your source files live in a
src/directory, run the command from the repo root and adjust the glob accordingly:
g++ -std=c++17 -O2 src/*.cpp -o huffman
Because different implementations wire up their CLI differently, run the produced binary directly:
./huffmanIf you want, tell me what arguments your main() expects (e.g. encode <in> <out> / decode <in> <out>) and I can update this README with the exact usage.
- Bit-level I/O (packed bits) for better compression ratios
- Persisting the codebook/tree in the output format
- Benchmarks and test vectors
Add a LICENSE file if you plan to reuse/distribute this project.