Skip to content

About

CSC10004 Project - Data Strucutre and Algorithms

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

String Compressor

A command-line string compression tool implementing three classic compression algorithms in C++17

Quick Start

# 1. Compile
g++ src/*.cpp -Iinclude -std=c++17 -O2 -o bin/compressor

# 2. Run (compress)
bin/compressor -a rle -m c -i tests/puzzle.txt -o output.rle

# 3. Verify (decompress)
bin/compressor -a rle -m d -i output.rle -o decoded.txt

Supported Algorithms

Algorithm Flag Description
Run-Length Encoding rle Compresses consecutive repeated bytes
Huffman Coding huff Variable-length prefix coding via binary tree (canonical)
Lempel-Ziv-Welch lzw Dictionary-based adaptive compression (fixed 16-bit codes)

Build

# Direct compile
g++ src/*.cpp -Iinclude -std=c++17 -O2 -o bin/compressor

# Or using Makefile
make

Clean build artifacts:

make clean

Usage

bin/compressor -a [rle|huff|lzw] -m [c|d] -i <input> -o <output>
Flag Description
-a Algorithm: rle, huff, or lzw
-m Mode: c (compress) or d (decompress)
-i Input file path
-o Output file path

Examples

Test file (tests/puzzle.txt): AAAAABBBBBCCCCCDDDDD

# RLE
bin/compressor -a rle  -m c -i tests/puzzle.txt -o output.rle
bin/compressor -a rle  -m d -i output.rle -o decoded.txt

# Huffman
bin/compressor -a huff -m c -i tests/puzzle.txt -o output.huff
bin/compressor -a huff -m d -i output.huff -o decoded.txt

# LZW
bin/compressor -a lzw  -m c -i tests/puzzle.txt -o output.lzw
bin/compressor -a lzw  -m d -i output.lzw -o decoded.txt

With any text file:

bin/compressor -a huff -m c -i myfile.txt -o myfile.huff
bin/compressor -a huff -m d -i myfile.huff -o myfile_restored.txt

Performance Output

After compression, the tool prints:

Compression complete.
--------------------------------
Algorithm: huff
Execution Time: 0.12 ms
Original Size: 20 bytes
Compressed Size: 15 bytes
Compression Ratio: 1.33
Space Savings: 25.00%
  • Compression Ratio = Original Size / Compressed Size
  • Space Savings = (1 - Compressed Size / Original Size) × 100%

Requirements

  • C++17 compiler (g++ 7+)
  • No external libraries — C++ Standard Library only

About

CSC10004 Project - Data Strucutre and Algorithms

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages