Skip to content

Library implementation of Huffman encoding for text compression and decompression. Written in C++.

License

Notifications You must be signed in to change notification settings

ivanreeve/text-compression-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Huffman Text Compression Library

stars watchers contributors commits

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.

Features

Supports large files while being performant

Profiling result shows sub 1000ms processing speed for up to 10 million characters.

Compression ratio reaches up to 50%

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

sample

Getting Started

To use this library in your C++ project, follow these steps:

  1. Clone the repository or download the source code.
  2. Include the necessary files in your project. Make sure that the header file is in the appropriate folder location.
  3. Use the provided functions for compression and decompression.

Interface

Compression

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.

Decompression

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.

Usage

#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;
}

Additional Notes

📝 What is Huffman Encoding?.

📝 storage format.

License

This project is licensed under the MIT License.

About

Library implementation of Huffman encoding for text compression and decompression. Written in C++.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages