Skip to content

Yilkici/fse-made-easy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FSE, made easy Build Status

Finite State Entropy (FSE) is an entropy coder which combines the speed of Huffman coding (which is suboptimal) with the compression ratio of arithmetic coding (which is slow). It is used in an optimized form within powerful compression schemes such as zstd and LZFSE.

Abridged fse.py:

def encode(stats, symbs):
    enc = 0
    for symb in symbs:
        s = stats[symb]
        div, mod = divmod(enc, s['prob'])
        enc = stats.total*div + mod + s['cdf']
    return enc

def decode(stats, enc):
    symbs = []
    while enc > 0:
        div, mod = divmod(enc, stats.total)
        s = stats.get_by_cdf(mod)
        enc = s['prob']*div + mod - s['cdf']
        symbs.insert(0, s['symb'])
    return symbs

About

Runnable pseudocode for Finite State Entropy compression

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%