Python implementation of carry-less range coder
Project description
Both static and dynamic encoding can be used.
Install
$ pip install CarryLessRangeCoder
Examples
from collections import Counter
import carryless_rangecoder as rc
from io import BytesIO
data = list(map(ord, 'qawsedrftgyhujikolp;'))
count = [1] * 256
for i, c in Counter(data).items():
count[i] += c
count_cum = [0] * 256
for i in range(1, 256):
count_cum[i] = count[i] + count_cum[i - 1]
out = BytesIO()
# Encode
with rc.Encoder(out) as enc: # or enc.finish()
for index in data:
enc.encode(count, count_cum, index)
# Decode
decoded = []
with rc.Decode(out) as dec: # or dec.start()
for _ in range(len(data)):
decoded.append(dec.decode(count, count_cum))
assert decoded == data
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
Close
Hashes for CarryLessRangeCoder-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5860128581bd2c3834960535175fd01974b0447c3442be831c15cfd6fe484b46 |
|
MD5 | a60518c2da922be3dc266c63ea5240f7 |
|
BLAKE2b-256 | 0e200bb3b5d598180ab0f56b002a42d378de4df6399e4c774ddde29108e56008 |