huffman
huffman
An implementation of Huffman algorithm in Crystal for learning purposes (using 0 and 1 in a String array).
To compress real files a new implementation using BitArray should be required.
A real usecase of Huffman coding is Zstandard and Huff0 used in kernel compresion
Huffman code is a particular type of optimal prefix code that is commonly used for lossless data compression.
Installation
-
Add the dependency to your
shard.yml
:dependencies: huffman: github: faustinoaq/huffman
-
Run
shards install
Usage
require "huffman"
h = Huffman.new # Using ASCII table
p h.encode("Hello World") # => 1111100111011011001001100100110001000111001010010110001011010001100100111010
h = Huffman.new("Hello World") # Using "Hello World"
p h.encode("Hello World") # => 01000101000001111011101110000101
p h.decode("01000101000001111011101110000101") # => Hello World
Development
$ crystal spec
......
Finished in 3.1 milliseconds
6 examples, 0 failures, 0 errors, 0 pending
Contributing
- Fork it (https://github.com/faustinoaq/huffman/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Faustino Aguilar - creator and maintainer
Repository
huffman
Owner
Statistic
- 1
- 0
- 0
- 0
- 0
- over 1 year ago
- March 9, 2023
License
MIT License
Links
Synced at
Sat, 23 Nov 2024 06:30:49 GMT
Languages