序列压缩? [英] Sequence Compression?
本文介绍了序列压缩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
a,b-->a,b
a,b,a,a,c-->a,b,a,a,c(不能压缩成a,b,a,c,因为这样会丢失a,a)
有没有什么算法可以做到这一点?这个问题叫什么?是压缩的吗?或者别的什么? 如果能有任何帮助,我将不胜感激 提前感谢
推荐答案
另一个很好的算法是Lempel–Ziv–Welch
我发现这个简单的Javascript LZW函数非常棒,来自140 bytes of javascript的魔术师:
function (
a // String to compress and placeholder for 'wc'.
){
for (
var b = a + "Ā", // Append first "illegal" character (charCode === 256).
c = [], // dictionary
d = 0, // dictionary size
e = d, // iterator
f = c, // w
g = c, // result
h; // c
h = b.charAt(e++);
)
c[h] = h.charCodeAt(), // Fill in the dictionary ...
f = 1 + c[a = f + h] ? a : (g[d++] = c[f], c[a] = d + 255, h); // ... and use it to compress data.
return g // Array of compressed data.
}
这篇关于序列压缩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文