mirror of
https://github.com/Kiritow/OpenComputerScripts.git
synced 2024-03-22 13:10:46 +08:00
update libcompress to avoid TLWY
This commit is contained in:
parent
cb3f0c16df
commit
306783ca2c
|
@ -2,6 +2,9 @@
|
||||||
-- Another version of libhuffman for general purpose
|
-- Another version of libhuffman for general purpose
|
||||||
-- Created by Kiritow
|
-- Created by Kiritow
|
||||||
-- Use Lua 5.3 feature
|
-- Use Lua 5.3 feature
|
||||||
|
-- This scripts can run with both OpenComputers and Standard Lua.
|
||||||
|
|
||||||
|
local keepUp=require("libkeepup")(4)
|
||||||
|
|
||||||
-- checkType(name,1,"string")
|
-- checkType(name,1,"string")
|
||||||
local function checkType(arg,id,which)
|
local function checkType(arg,id,which)
|
||||||
|
@ -170,6 +173,8 @@ local function hdef(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
keepUp()
|
||||||
|
|
||||||
local pool={}
|
local pool={}
|
||||||
for k,v in pairs(ctb) do
|
for k,v in pairs(ctb) do
|
||||||
table.insert(pool,{k,v})
|
table.insert(pool,{k,v})
|
||||||
|
@ -177,6 +182,7 @@ local function hdef(data)
|
||||||
|
|
||||||
local poolsz=#pool
|
local poolsz=#pool
|
||||||
repeat
|
repeat
|
||||||
|
keepUp()
|
||||||
table.sort(pool,function(a,b) return a[2]>b[2] end)
|
table.sort(pool,function(a,b) return a[2]>b[2] end)
|
||||||
local t={nil,pool[poolsz-1][2]+pool[poolsz][2],L=pool[poolsz-1],R=pool[poolsz]}
|
local t={nil,pool[poolsz-1][2]+pool[poolsz][2],L=pool[poolsz-1],R=pool[poolsz]}
|
||||||
table.remove(pool)
|
table.remove(pool)
|
||||||
|
@ -188,6 +194,7 @@ local function hdef(data)
|
||||||
local dic={}
|
local dic={}
|
||||||
local writer=BitWriter.new()
|
local writer=BitWriter.new()
|
||||||
local function _encode_tree(node,prefix)
|
local function _encode_tree(node,prefix)
|
||||||
|
keepUp()
|
||||||
if(node[1]) then
|
if(node[1]) then
|
||||||
writer:pushbit(1)
|
writer:pushbit(1)
|
||||||
writer:pushbits(charToBitStr(node[1]))
|
writer:pushbits(charToBitStr(node[1]))
|
||||||
|
@ -205,10 +212,14 @@ local function hdef(data)
|
||||||
end
|
end
|
||||||
_encode_tree(pool[1],"")
|
_encode_tree(pool[1],"")
|
||||||
|
|
||||||
|
keepUp()
|
||||||
|
|
||||||
for i=1,data:len() do
|
for i=1,data:len() do
|
||||||
writer:pushbits(dic[data:sub(i,i)])
|
writer:pushbits(dic[data:sub(i,i)])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
keepUp()
|
||||||
|
|
||||||
local defdata,defpad=writer:get()
|
local defdata,defpad=writer:get()
|
||||||
return string.pack(">B",defpad) .. defdata
|
return string.pack(">B",defpad) .. defdata
|
||||||
end
|
end
|
||||||
|
@ -236,6 +247,7 @@ local function hinf(data)
|
||||||
local output=''
|
local output=''
|
||||||
local working=''
|
local working=''
|
||||||
while true do
|
while true do
|
||||||
|
keepUp()
|
||||||
local b=reader:nextbit()
|
local b=reader:nextbit()
|
||||||
if(not b) then break end
|
if(not b) then break end
|
||||||
working=working .. b
|
working=working .. b
|
||||||
|
|
Loading…
Reference in New Issue
Block a user