Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

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

Stars

30 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages