Simple Huffman algotithm implementation
Project description
Huffify
Description
Huffify allows you to compress text using Huffman algorithm. Huffify focus on flexibility - you can choose various encoders, huffman tree nodes and file managers to rich the best compressing quality
Historical note: The Huffman algorithm was developed by David A. Huffman in 1952. Read more about David and his algorithm
Usage
Basic usage
from huffify import HuffmanCodec
from huffify.heapNodes import Node, LexicographicNode
from huffify.encoders import MVPEncoder
# You can use LexicographicNode that provide idempotent result and another encoder.
# Now this node and encoder set as default attributes
codec = HuffmanCodec(node=Node, encoder=MVPEncoder)
message = "The sun shines bright today."
# Here is the "FinalDataSet", which can be saved as file
encoded_message = codec.encode(message)
# Also you can decode this "FinalDataSet" to get original message
decoded_message = codec.decode(encoded_message)
Advanced usage
from huffify import Huffify
from huffify.fileManager import Picklefier
# You can pass preferred writing into file strategy
# It's only one yet and it thrown into Huffify as default strategy
file_compressor = Huffify(file_manager=Picklefier)
# You can save your compressed message into file
file_compressor.save(path="output", message="The sun shines bright today.")
# And also load and decompress it
decoded_message = file_compressor.load(path="output")
Watch encoding table
from huffify import HuffmanCodec
codec = HuffmanCodec()
message = "The sun shines bright today."
# If you want get encoding table as dict
encoding_table = codec._get_encoding_table(message)
# Also you can print the encoding at representative view
codec.print_encoding_table(message)
Installation
Using pip
pip install huffify
Using poetry
poetry add huffify
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
huffify-0.2.0.tar.gz
(5.1 kB
view details)
Built Distribution
File details
Details for the file huffify-0.2.0.tar.gz
.
File metadata
- Download URL: huffify-0.2.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.5.0-1018-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fafe0a28ac6522cf61366943b8e3afb05c6ed1a952a3ce1ef7781f45b40306f7 |
|
MD5 | 540d3dfec7a1813dd4b14f9c04a44212 |
|
BLAKE2b-256 | 74c516b38de829f1de1d8a44622bd1d0f90fa31cfcef57633f99198b9aa690bb |
File details
Details for the file huffify-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: huffify-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.5.0-1018-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d12fd09a7b9d07f23512480e921bbe745bb638a035234788fbe2606798e8e4ed |
|
MD5 | c482d94e6014ed926ca2f81bc35f7173 |
|
BLAKE2b-256 | 8d853832b00e639a8520df107b3d0397ca1d005df684fe2e7eb55f373d4a544d |