compressionlzw

LZW for fractional values and other data values


There are many examples provided over the internet for encoding strings using LZW however how this algorithm encode fractional values? Do we consider every input to the LZW as string i.e. suppose I have an array of fractional values: for example [2.12345 -2.225588 1.236547 25] does the LZW encode this by considering it as a string s = "2.12345 -2.225588 1.236547 25". With alphabets I understand but regarding other types of data like real numbers, binary data etc, how does LZW creates dictionary?


Solution

  • LZW, as presented in the original article, encodes bytes, period. What and how you encode data in those bytes is up to you. For the data you are showing, you would be better off starting with the numbers encoded in binary, and only to the accuracy inherent in the data.

    Note that LZW is an ancient and obsolete compression method. You should look at more modern compressors, such as lz4, zstd, and lzma2.