LZW Compression In Lua

后端 未结 2 1367
日久生厌
日久生厌 2020-12-12 04:44

Here is the Pseudocode for Lempel-Ziv-Welch Compression.

 pattern = get input character
 while ( not end-of-file ) {
     K = get input character
     if (          


        
相关标签:
2条回答
  • 2020-12-12 04:51

    You should also take a look here to download the source for a high-performance LZW compression algorithm in Lua...

    0 讨论(0)
  • 2020-12-12 05:10

    Assuming uncompressed is a string, you'll need to use something like this to iterate over it:

    for i = 1, #uncompressed do
      local c = string.sub(uncompressed, i, i)
      -- etc
    end   
    

    There's another issue on line 10; .. is used for string concatenation in Lua, so this line should be local wc = w .. c.

    You may also want to read this with regard to the performance of string concatenation. Long story short, it's often more efficient to keep each element in a table and return it with table.concat().

    0 讨论(0)
提交回复
热议问题