L7ZZ compression algorithm

LZ77 compression algorithm


LZ77是一种基于字典的算法,它将长字符串(也称为短语)编码成短小的标记,用小标记代替字典中的短语,从而达到压缩的目的。

	LZ77使用的是一个前向缓冲区和一个滑动窗口来维护字典。它首先将一部分数据载入前向缓冲区,一旦数据
中的短语通过前向缓冲区,那么它将移动到滑动窗口中,并变成字典的一部分,随着滑动窗口移动,字典中的内
容也在不断的更新,也就是说它是变更新字典,边进行压缩。

	假设字典已经建立,每读到一个字符,就向前扫描,在字典中查看是否有重复出现的短语,若搜索出有重复
出现的短语,将其编码成短语标记。短语标记由三部分组成:滑动窗口中的偏移量(从头部到匹配开始的前一个
字符)、匹配中的符号个数、匹配结束后,前向缓冲区中的第一个符号---(offset, lenght, nextChar)。当
没有找到匹配时,将未匹配的符号编码成符号标记。这个符号标记仅仅包含符号本身,没有压缩过程。一旦把n个
符号编码并生成相应的标记,就将这n个符号从滑动窗口的一端移出,并用前向缓冲区中同样数量的符号来代替它
们。然后,重新填充前向缓冲区。

The following figure shows the LZ77 compression process, assuming sliding window size is 8 bytes, forward buffer size is 4 bytes:
Here Insert Picture Description
Here Insert Picture Description
When the decoding of each mark, the mark encoded into characters copied to the sliding window. Whenever there is a phrase marker to find the appropriate offset in the sliding window, while for the specified length of phrases found there. Whenever there is a sign marked, it generates a symbol saved tag

Here Insert Picture Description

Published 230 original articles · won praise 28 · views 9308

Guess you like

Origin blog.csdn.net/weixin_43767691/article/details/103778967