Here is the Pseudocode for Lempel-Ziv-Welch Compression.
pattern = get input character
while ( not end-of-file ) {
K = get input character
if (
You should also take a look here to download the source for a high-performance LZW compression algorithm in Lua...
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()
.