Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amicks/huffman-coding
Utilizes Huffman's lossless data compression algorithm to encode/decode files. Final project in CMPS12B.
https://github.com/amicks/huffman-coding
Last synced: about 1 month ago
JSON representation
Utilizes Huffman's lossless data compression algorithm to encode/decode files. Final project in CMPS12B.
- Host: GitHub
- URL: https://github.com/amicks/huffman-coding
- Owner: amicks
- Created: 2017-06-12T20:55:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-09-04T00:07:23.000Z (about 7 years ago)
- Last Synced: 2024-10-09T09:50:15.831Z (about 1 month ago)
- Language: C
- Homepage:
- Size: 713 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
###### Author: Allston Mickey
## Files:
* bv.h
* code.h
* decode.c
* encode.c
* heap.h
* huffman.c, huffman.h
* queue.c, queue.h
* stack.c, stack.h
* Makefile## How to compile & run:
Command | Description
--- | ---
make | Compiles the encode and decode programs.
make all | Compiles the encode and decode programs.
make encode | Compiles the encode program.
make decode | Compiles the decode program.
make clean | Remove the object files and encode/decode binaries
./encode _[flags]_ | Run the encode program.
./decode _[flags]_ | Run the decode program.## Flags:
Argument(s) | Description | Coding Type
--- | --- | ---
-i _[path]_ | Full path to the input file | Both **_[REQUIRED]_**
-o _[path]_ | Full path to the output file | Both
-A | Sets all flags (-vp, -ch if available) | Both
-v | Enable verbose mode - prints statistics about the program | Both
-p | Prints the Huffman Tree | Both
-c | Prints the codes/bit paths to each leaf in the Huffman Tree | Encoding
-h | (./encode only) Prints the histogram of bytes | Encoding## Description:
These programs encode/decode any file by using the greedy Huffman Algorithm.
#### [encoding]
1. Construct a histogram of the bytes in a file.
2. Enqueue each histogram entry as a node in the Huffman Tree.
3. Repeatedly dequeue 2X and enqueue until the root of the tree is remaining.
4. Load the codes for each leaf by a post-order traversal of the tree, assigning a 0 when traversing left and a 1 when traversing right. Store the codes in a bit vector for maximum efficiency.
5. Write the tree and the paths to each leaf to an encoded output file.#### [decode]
1. Read the encoded file.
2. Reconstruct the Huffman Tree with a stack.
3. For each byte in the original, uncompressed file, look up its code and step through the tree.
4. Write the bytes back to a decoded output file.
---
* Using both programs, any file can be encoded and then decoded back to an exact copy of the original.
* Note that the default permissions to a file are 0744 (-rwxr--r--).
You may change these on your own if they do not suit what you intended.