Function Lua中的LZW压缩
这是Lempel-Ziv-Welch压缩的伪代码Function Lua中的LZW压缩,function,dictionary,lua,compression,lzw,Function,Dictionary,Lua,Compression,Lzw,这是Lempel-Ziv-Welch压缩的伪代码 pattern = get input character while ( not end-of-file ) { K = get input character if ( <<pattern, K>> is NOT in the string table ){ output the code for pattern add <&
pattern = get input character
while ( not end-of-file ) {
K = get input character
if ( <<pattern, K>> is NOT in
the string table ){
output the code for pattern
add <<pattern, K>> to the string table
pattern = K
}
else { pattern = <<pattern, K>> }
}
output the code for pattern
output EOF_CODE
我真的希望得到一些帮助,或者让我的代码运行,或者帮助我在Lua中编写LZW压缩。非常感谢你 假设
uncompressed
是一个字符串,则需要使用类似以下内容来迭代它:
for i = 1, #uncompressed do
local c = string.sub(uncompressed, i, i)
-- etc
end
第10行还有一个问题<代码>。用于Lua中的字符串连接,因此此行应为local wc=w。。c
您可能还想了解字符串连接的性能。长话短说,将每个元素保存在一个表中并返回时使用
table.concat()
通常效率更高。您还应该查看下载Lua中的高性能LZW压缩算法的源代码…抱歉,我对这一点很陌生。。。但是--etc评论之后应该是什么呢?非常感谢你!它运行没有错误!非常感谢。我现在的小问题是它正在打印“表:0x7861e7f0”。。。谢谢此外,我尝试将“return dictionary”更改为“return w”,并将其移动到for循环中,但现在它只打印“T”。返回表。concat(dictionary)
将其作为字符串输出。现在它打印“”,没有任何内容。可能重复:可能重复的Ah,但它展示了一些很好的Lua技术,这些技术可能很有用
for i = 1, #uncompressed do
local c = string.sub(uncompressed, i, i)
-- etc
end