algorithm - LZW数据解压算法

标签 algorithm compression

我一直在研究 LZW algorithm 最近用于数据压缩。我已经了解编码算法,但是,我无法理解将编码数据转换回原始形式的解码算法。

以下是取自 here 的解码器伪代码

string entry;
char ch;
int prevcode, currcode;
...

prevcode = read in a code;
decode/output prevcode;
while (there is still data to read)
{
  currcode = read in a code;
  entry = translation of currcode from dictionary;
  output entry;
  ch = first char of entry;
  add ((translation of prevcode)+ch) to dictionary;
  prevcode = currcode;
}

我正在寻找此代码的分步说明。

编辑:我不明白的是:为什么我们有 3 个不同的字符串,即 entryprevcodecurrcode ?在我看来,一个应该是编码字符串,第二个应该是创建的输出字符串。那么第三根弦在那里做什么呢?

其次,我真的不明白代码倒数第二行(prevcode的翻译)+ch的用意。

谢谢。

最佳答案

如果您了解压缩部分,您也应该能够理解,要使解压工作,解压器需要从解压数据重建压缩表,就像在压缩期间构建的一样——否则进来的代码不是纯字符代码将毫无意义。这就是这些额外语句的作用。

关于algorithm - LZW数据解压算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18771559/

相关文章:

algorithm - 使用递归排序

algorithm - 从 A 中找到文章 B 中的连续单词

android - Bitmap.compress 不会减少字节数

java - 在 Flex 和 Java 中压缩和解压缩 XML

javascript - jszip 中的压缩文件比未压缩的内容大

image - 相似图像压缩

c++ - 费舍尔耶茨变例

algorithm - 变半径圆覆盖算法

algorithm - 三角形中的样本随机点

Java - 计算文件压缩