Giter VIP home page Giter VIP logo

huffman-text-compression-library's Introduction

Huffman Text Compression Library

This C++ library is my own implementation of Huffman compression and decompression algorithm. Only works 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 two separate files and was later combined into a single library.

Features

Supports Large Files

The library can handle large files (10,000,000+ characters) surprisingly well.

Larger files may take longer time to finish.

Up to 50% Compression Ratio

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.

Functions

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

๐Ÿ“ The storage format for compression was also inspired by Lasse V. Karlsen's proposal.

License

This project is licensed under the MIT License.

huffman-text-compression-library's People

Contributors

ivanreeve avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.