Giter VIP home page Giter VIP logo

bhumijgupta / huffman-compression-library Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 1.0 253 KB

A light weight C++ library implementation of huffman coding compression algorithm

Home Page: https://bhumijgupta.github.io/huffman-compression-library/

License: MIT License

C++ 98.02% CMake 1.98%
cpp huffman-coding file-compression huffman-compression-algorithm huffman-compression-library compression-algorithm c c-plus-plus cpp-library

huffman-compression-library's Introduction

HCL (Huffman Compression Library)

HCL a custom C++ library that allows file compression using Huffman Compression algorithm.

Codacy Badge GitHub repo size GitHub code size in bytes GitHub top language

Table of Contents

Features

  • Fast and efficient
  • Supports all kinds of files (images, pdf, video, text, etc)
  • High level abstraction methods to be used
  • No need of understanding how compression algorithm works
  • Light weight library
  • Compression ratio of upto 50%

Benchmarks

Below is the output for huffmantool.benchmark() method output.png

Usage

There are 2 ways to try the HCL library

1. Try Online

Try the HCL library online on my custom repl.

2. Try Locally

  1. Clone this repo to your project folder
    git clone https://github.com/bhumijgupta/huffman-compression-library.git hcl

  2. Import Huffman tool header and create new huffmantool object

// Filename main.cpp
#include "hcl/huffmantool.h"

int main(){
    huffmantool ht;
    .
    .
    .
}
  1. Compile and run file
g++ main.cpp && ./a.out

Methods

compressFile

compressFile(string sourceFile, string compressedFile = "") : string

Returns the destination of compressed file.
If the sourceFile provided is invalid or cannot be opened, it returns an empty string.

If no compressedFile is provided, compressedFile is present at the same dir as sourcefile with prefix compressed_

decompressFile

decompressFile(string compressedFile, string retrievedFile = "") : string

Returns the destination of decompressed file.
If the compressedFile provided is invalid or cannot be opened, it reurns an empty string.

If no retrievedFile is provided, retrievedFile is present at the same dir as compressedFile with prefix decompressed_ and removed compressed_ prefix (if present)

benchmark

benchmark(string sourcefile) : void

This method performs compression and decompression on the sourcefile provided and prints the following stats to the stdout.

--------------------------------------------------------------------------------
                              B E N C H M A R K
--------------------------------------------------------------------------------

Filetype                      Filename                      Filesize in bytes

Original
Compressed
Decompressed

--------------------------------------------------------------------------------
Time taken to compress file: XYZ microseconds
Time taken to decompress file: XYZ microseconds
Compression: XY.Z%

Note: For detailed understanding of code refer to Wiki.

Performance Comparison

The newfile.txt is populated using lorem ipsum data from lipsum.com and the following data is noticed after executing main.cpp.

Number of characters Original file size (in bytes) Compressed file size (in bytes)
10 10 36
100 100 116
1000 1000 642
10000 10000 5445
100000 100000 53354

Conclusion

The compression ratio and performance of the Huffman coding depends on the size of input text and the frequency of distinct characters in the file. From the above comparison we can see that the current implementation of huffman coding does not produce positive compression ratio for small files due to the overhead of storing Huffman Tree in the compressed file, which is useful at the time of decompression.

But we notice, as the size of file increases (>=1000 bytes), the compression ratio stays at almost 50%.

Examples

Following are the list of examples

Run tests

The tests are stored in tests/ directory. You need to install googletest framework to run test.

cd tests/
cmake CMakeLists.txt
make
./runTests

License

GitHub

This library is licensed under MIT License. The license file can be found here

Author

forthebadge

Bhumij Gupta

GitHub followers LinkedIn Twitter URL


if(repo.isAwesome || repo.isHelpful){
    StarRepo();
}

huffman-compression-library's People

Contributors

bhumijgupta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

noticeable

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.