【数据压缩】LZ77算法原理及实现

【数据压缩】LZ78算法原理及实现

Lempel–Ziv–Welch


年发表的论文《A Universal Algorithm for Sequential Data Compression》中提出。

基于统计的数据压缩编码,比如Huffman编码,需要得到先验知识——信源的字符频率,然后进行压缩。但是在大多数情况下,这种先验知识是很难预先获得。

因此,设计一种更为通用的数据压缩编码显得尤为重要。LZ77数据压缩算法应运而生,其核心思想:利用数据的重复结构信息来进行数据压缩。

LZ77: referring to previously processed data as dictionary 利用内部信息作为字典。

在提出基于滑动窗口的LZ77算法后,两位大神Jacob ZivAbraham Lempel于年在发表的论文中提出了LZ78算法

与LZ77算法不同的是LZ78算法使用动态树状词典维护历史字符串。

LZ78: use an explicit dictionary 字典是外置的。

LZ系列压缩算法均为LZ77LZ78的变种,在此基础上做了优化。

  • LZ77LZSS、LZR、LZB、LZH;
  • LZ78LZW、LZC、LZT、LZMW、LZJ、LZFG。

LZW Encoding:

  Video: https://www.youtube.com/watch?v=nW7OARbr7OI

"TO BE OR NOT TO BE OR TO BE OR NOT"

Idea:

以下是我们已知的字典。

再动态补充新发现的pattern字典,从27开始编号,如下所示:

current next code dictionary  
T O 20 TO 27 TO BE OR NOT TO BE OR TO BE OR NOT
O B 15 OB 28 TO BE OR NOT TO BE OR TO BE OR NOT
B E 2 BE 29 TO BE OR NOT TO BE OR TO BE OR NOT
E O 5 EO 30 TO BE OR NOT TO BE OR TO BE OR NOT
O R 15 OR 31 TO BE OR NOT TO BE OR TO BE OR NOT
R N 18 RV 32 TO BE OR NOT TO BE OR TO BE OR NOT
N O 14  NO  33  TO BE OR NOT TO BE OR TO BE OR NOT
O 15  OT  34  TO BE OR NOT TO BE OR TO BE OR NOT
T T 20 TT  35  TO BE OR NOT TO BE OR TO BE OR NOT
TO B 27 TOB 36  TO BE OR NOT TO BE OR TO BE OR NOT
BE O 29  BEO 37  TO BE OR NOT TO BE OR TO BE OR NOT
OR 31  ORT  38  TO BE OR NOT TO BE OR TO BE OR NOT
TOB 36  TOBE  39  TO BE OR NOT TO BE OR TO BE OR NOT
EO 30  EOR  40  TO BE OR NOT TO BE OR TO BE OR NOT
RN O 32 RNO 41 TO BE OR NOT TO BE OR TO BE OR NOT
OT # 34 N/A N/A TO BE OR NOT TO BE OR TO BE OR NOT
Input   Output      

这里共16行,也就是原来的24字节 --> 16字节。

LZW Decoding:

code prev output dictionary  
20   T     TO BE OR NOT TO BE OR TO BE OR NOT
15 T O TO 27 TO BE OR NOT TO BE OR TO BE OR NOT
2 O B OB 28 TO BE OR NOT TO BE OR TO BE OR NOT
5 B E BE 29 TO BE OR NOT TO BE OR TO BE OR NOT
15 E O EO 30 TO BE OR NOT TO BE OR TO BE OR NOT
18 O R OR 31 TO BE OR NOT TO BE OR TO BE OR NOT
14 R N RN 32 TO BE OR NOT TO BE OR TO BE OR NOT
15 N O NO 33 TO BE OR NOT TO BE OR TO BE OR NOT
20 O T OT 34 TO BE OR NOT TO BE OR TO BE OR NOT
27 T TO TT 35 TO BE OR NOT TO BE OR TO BE OR NOT
29 TO BE TOB 36 TO BE OR NOT TO BE OR TO BE OR NOT
31 BE OR BEO 37 TO BE OR NOT TO BE OR TO BE OR NOT
36 OR TOB ORT 38 TO BE OR NOT TO BE OR TO BE OR NOT
30 TOB EO TOBE 39 TO BE OR NOT TO BE OR TO BE OR NOT 
32 EO RN EOR 40 TO BE OR NOT TO BE OR TO BE OR NOT 
34 RN OT RNO 41 TO BE OR NOT TO BE OR TO BE OR NOT 
 <Output>   <Input>      

可见与encoding时表格一一对应的关系。

就是还原表格的过程。

[IR] Dictionary Coding的更多相关文章

  1. [IR] Huffman Coding

    为了保证:Block中,所有的叶子在所有的中间结点的前面.Static: Huffman coding Dynamic: Adaptive Huffman 一些概念 压缩指标 • Compress a ...

  2. [IR] Arithmetic Coding

    Statistical methods的除了huffman外的另一种常见压缩方式. Huffman coding的非连续数值特性成为了无法达到香农极限的先天无法弥补的缺陷,但Arithmetic co ...

  3. 本人AI知识体系导航 - AI menu

    Relevant Readable Links Name Interesting topic Comment Edwin Chen 非参贝叶斯   徐亦达老板 Dirichlet Process 学习 ...

  4. [Code] 烧脑之算法模型

    把博客的算法过一遍,我的天呐多得很,爱咋咋地! 未来可考虑下博弈算法. 基本的编程陷阱:[c++] 面试题之犄角旮旯 第壹章[有必要添加Python] 基本的算法思想:[Algorithm] 面试题之 ...

  5. HANA Architecture

    1 HANA 是基于内存计算的.行列都支持.使用列存储,列存储的特点是高压缩,查询快,节约空间, ---SAP HANA supports both, but is particularly opti ...

  6. python之最强王者(8)——字典(dictionary)

    1.Python 字典(Dictionary) 字典是另一种可变容器模型,且可存储任意类型对象. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典包 ...

  7. Dictionary Learning(字典学习、稀疏表示以及其他)

    第一部分 字典学习以及稀疏表示的概要 字典学习(Dictionary Learning)和稀疏表示(Sparse Representation)在学术界的正式称谓应该是稀疏字典学习(Sparse Di ...

  8. Coding源码学习第一部分(AppDelegate.m)

    前言:在此首先感谢开源,感谢大神们的无私分享. Coding 的主页:https://coding.net/app#app-feature Coding 自己家的仓库:https://coding.n ...

  9. [IR] Compression

    关系:Vocabulary vs. collection size Heaps’ law: M = kTbM is the size of the vocabulary, T is the numbe ...

随机推荐

  1. Git:本地建服务器及入门使用方法

    1. 安装与配置Git服务器 sudo apt-get install git 1.1 注册一个git账号, 用于运行和维护git sudo adduser git 1.2 创建证书登录: 收集所有需 ...

  2. UEditor实现前后端分离时单图上传

    首先,需要下载部署ueditor相关代码,可以参考一篇简单的博客,这里不再赘述: 环境搭建好后,我们先简单使用一下,启动http://web.yucong.com:8080/ueditor/index ...

  3. 集合(4)—Collection之Set的使用方法

    定义 set接口及其实现类–HashSet Set是元素无序且不可重复的集合,被称为集. HashSet是哈希集,是Set的一个重要实现类 set中循环只能使用foreach和iterator这两个, ...

  4. 继承之final关键字的使用

    final关键字 使用final关键字坐标识具有"最终的"含义, final可以修饰类.方法.属性.和变量. final修饰类表示该类不能被继承 final修饰方法,则表示该方法不 ...

  5. TXB0108 TXS0108E 8-Bit Bidirectional Voltage-Level Translator for Open-Drain and Push-Pull Applications

    TXS(开漏优化设计),如I2C TXB(上拉优化设计),如SPI TXS0108 has integrated pull-up resistors to save board space and c ...

  6. Window Server 2008 R2 TFS2010 安装前的准备

    前言 http://www.cnblogs.com/aehyok/p/3979707.html 这里简单介绍了安装windows Server 2008 R2系统,接下来就开始介绍安装Team Fou ...

  7. Image Processing in Python with Pillow

    Introduction A lot of applications use digital images, and with this there is usually a need to proc ...

  8. Spark2.2+ES6.4.2(三十二):ES API之index的create/update/delete/open/close(创建index时设置setting,并创建index后根据avro模板动态设置index的mapping)

    要想通过ES API对es的操作,必须获取到TransportClient对象,让后根据TransportClient获取到IndicesAdminClient对象后,方可以根据IndicesAdmi ...

  9. 阮一峰的js教程,值得一读

    http://javascript.ruanyifeng.com/introduction/intro.html

  10. SPLIT_STR

    CREATE DEFINER=`root`@`%` FUNCTION `vir`.`SPLIT_STR`( x VARCHAR(1000), delim VARCHAR(12), pos INT) R ...