LZW compression: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: make the types more general) |
m (Optimized Lua decompress using table.concat. On 1.2mb test data, ~44x faster. 58.8s to 1.3s) |
||
Line 2,908: | Line 2,908: | ||
local function decompress(compressed) -- table |
local function decompress(compressed) -- table |
||
local dictionary, dictSize, entry, result, w, k = {}, |
local dictionary, dictSize, entry, result, w, k = {}, 0, "", {}, "" |
||
for i = 0, 255 do |
for i = 0, 255 do |
||
dictionary[i] = string.char(i) |
dictionary[i] = string.char(i) |
||
Line 2,921: | Line 2,921: | ||
return nil, i |
return nil, i |
||
end |
end |
||
result |
table.insert(result, entry) |
||
dictionary[dictSize] = w .. string.sub(entry, 1, 1) |
dictionary[dictSize] = w .. string.sub(entry, 1, 1) |
||
dictSize = dictSize + 1 |
dictSize = dictSize + 1 |
||
w = entry |
w = entry |
||
end |
end |
||
return result |
return table.concat(result) |
||
end |
end |
||