lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Almost solved!
64 is better than 256, but still not good enough
Try to use the same idea to reduce hash part size to 8 hash slots.


Why not just one slot? Reading out the slot could take a while but if we go for hash slots...

-- comressor.lua
local function Index(i)
    if i >= 0 and i < 100 then i = i + 0.5 end
    return i
end

local function Encode(what)
    local tab = {}
    local key = Index(what)
    tab[key] = true
    tab[key] = nil
    return tab
end

return Encode(...)

-- decompressor.lua
local function TestIndex(tab, i)
    if i >= 0 and i < 100 then i = i + 0.5 end
    return pcall(next, tab, i)
end

local function Decode(tab)
    local num = 0
    while true do
        if TestIndex(tab, num) then return num end
        num = num + 1
    end
end

return Decode(...)

Regards,
Xmilia