Move-to-front transform: Difference between revisions

Content deleted Content added
No edit summary
Line 81:
<syntaxhighlight lang="python">
# mtfwiki.py
 
from typing import Tuple, Union
# Instead of always transmitting an "original" dictionary, it is simpler to just agree on an initial set.
# Here we use the 256 possible values of a byte:
Line 132:
<syntaxhighlight lang="pycon">
>>> import mtfwiki
>>> mtfwiki.encode('"Wikipedia'")
[87, 105, 107, 1, 112, 104, 104, 3, 102]
>>> mtfwiki.decode([119, 106, 108, 1, 113, 105, 105, 3, 103])
Line 145:
>>> # Sort the ASCII blocks: first lowercase, then uppercase, punctuation/number, and finally the control code and the non-ASCII stuff
>>> mtfwiki.common_dictionary = block32(0x60) + block32(0x40) + block32(0x20) + block32(0x00) + list(range(128, 256))
>>> mtfwiki.encode('"Wikipedia'")
[55, 10, 12, 1, 17, 9, 9, 3, 7]
</syntaxhighlight>