Originally Posted by

**Jarek**
- tANS can have included encryption by choosing coding tables.

The decoding itself is very similar

tANS decoding step:

{t = decodingTable[x];

produce_symbol(t.symbol);

x = t.newX | readBitsFromStream(t.NumberOfBits);

}

Huffman is exactly the same (can be seen as a special case), but instead of storing t.newX, it is

t.newX = (x << t.NumberOfBits) & mask

For example in the standard case of L=2^11 number of states and m=2^8 alphabet, t.NumberOfBits requires L*4 bits, t.symbol requires L*8 bits. Storing t.newX requires additional L*11 bits - naively doubling the memory cost of decoding tables. Total ~6kB for tANS tables vs ~3kB for Huffman.

However, L=2^11 is restriction to at most 11bit codes in Huffman language, what is a crucial restriction for 8bit alphabet (more realistic for Huffman here is 12bit limit, what means also ~6 kB decoding tables). tANS is more flexible here and its preciseness usually allows to get better compression ratio with smaller number of states and so smaller memory requirement for decoding tables.

tANS encoding tables require <4kB here.