Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Huffman Encoder (C++)

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).

What this repo contains

  • A basic Huffman encoder/decoder implementation in C++
  • Code that uses standard C++ features (including smart pointers) to build and traverse the Huffman tree

How it works (high level)

  1. Count frequency of each symbol in the input
  2. Build a Huffman tree using a priority queue (min-heap)
  3. Generate prefix-free binary codes by traversing the tree
  4. Encode the input into a bitstream using the generated codes
  5. Decode by walking the tree according to bits

Build

This repository is intentionally lightweight and should compile with a standard g++ toolchain.

g++ -std=c++17 -O2 *.cpp -o huffman

If 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

Run

Because different implementations wire up their CLI differently, run the produced binary directly:

./huffman

If 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.

Notes / improvements you might add

  • Bit-level I/O (packed bits) for better compression ratios
  • Persisting the codebook/tree in the output format
  • Benchmarks and test vectors

License

Add a LICENSE file if you plan to reuse/distribute this project.

About

huffman encoder in C++ using unique ptrs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages