Skip to content

Commit

Permalink
Merge pull request kennyledet#378 from godspeed1989/fix_LZW
Browse files Browse the repository at this point in the history
fix LZW decode error
  • Loading branch information
jcla1 committed Jun 26, 2014
2 parents fefc6bd + 0e3f00f commit f6d8065
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Lempel_Ziv_Welch/Lua/Yonaba/lzw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
local function lzw_encode(str)
local w = ''
local result = {}
local dict_size = 255
local dict_size = 256

-- Builds the dictionnary
local dict = {}
for i = 0, dict_size do
for i = 0, dict_size-1 do
dict[string.char(i)] = i
end

Expand All @@ -23,8 +23,8 @@ local function lzw_encode(str)
else
-- Add the match to the dictionary
table.insert(result, dict[w])
i = i + 1
dict[wc] = i
i = i + 1
w = char
end
end
Expand All @@ -35,11 +35,11 @@ local function lzw_encode(str)
end

local function lzw_decode(str)
local dict_size = 255
local dict_size = 256

-- Builds the dictionary
local dict = {}
for i = 0, dict_size do
for i = 0, dict_size-1 do
dict[i] = string.char(i)
end

Expand All @@ -56,8 +56,8 @@ local function lzw_decode(str)
return nil -- No match found, decoding error
end
result = result .. entry
dict_size = dict_size + 1
dict[dict_size] = w .. entry:sub(1,1)
dict_size = dict_size + 1
w = entry
end
return result
Expand Down

0 comments on commit f6d8065

Please sign in to comment.