File | Date | Author | Commit |
---|---|---|---|
.github | 2020-01-02 |
![]() |
[55fb58] * Added documentation for examples |
assets | 2019-12-27 |
![]() |
[c3ec12] Fixed compression ratio |
examples | 2020-01-03 |
![]() |
[7c410b] Fix compiler issues in huffmantool and benchmar... |
sample | 2019-12-26 |
![]() |
[283a1d] * Converted to library huffmantool.h |
src | 2020-01-03 |
![]() |
[a83893] * Fixed g++ -Wall warnings |
tests | 2020-01-02 |
![]() |
[f1b2e5] Added unittests, moved CMakeLists and modified ... |
.gitignore | 2020-01-03 |
![]() |
[a83893] * Fixed g++ -Wall warnings |
LICENSE | 2019-12-27 |
![]() |
[39746f] Add MIT License |
README.md | 2020-01-02 |
![]() |
[9d83f3] * Fixed double declaration of string output in ... |
_config.yml | 2019-12-25 |
![]() |
[48ad34] Jekyll website config |
huffmantool.h | 2020-01-03 |
![]() |
[ff27c4] Added documentation for public class |
HCL a custom C++ library that allows file compression using Huffman Compression algorithm.
Below is the output for huffmantool.benchmark()
method
There are 2 ways to try the HCL library
Try the HCL library online on my custom repl.
Clone this repo to your project folder
git clone git@github.com:bhumijgupta/huffman-compression-library.git hcl
Import Huffman tool header and create new huffmantool
object
// Filename main.cpp
#include "hcl/huffmantool.h"
int main(){
huffmantool ht;
.
.
.
}
g++ main.cpp && ./a.out
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(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(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.
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 |
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%.
Following are the list of examples
The tests are stored in tests/
directory. You need to install googletest framework to run test.
cd tests/
cmake CMakeLists.txt
make
./runTests
This library is licensed under MIT License. The license file can be found here
if(repo.isAwesome || repo.isHelpful){
StarRepo();
}