您能给我一些解释LZ77算法吗?
我正在尝试和我的朋友学习LZ77算法,有些情况让我们感到困惑。
例如)
初始化
- 搜索缓冲区大小:7
- 前瞻缓冲区大小:8
- 原始字符串:abcabbcabbcabca
- 当前 窗口:abcabbc 视图:abbcabca
我认为 LLD 元组是: 字面意思:'a' 长度:4 距离:4
我朋友认为 LLD 元组是: 字面意思:“c” 长度:6 距离:4
我认为查找最长匹配字符串的算法仅检查搜索缓冲区,但他说查找匹配字符串没有限制。
谁的答案是正确的?
I'm trying to learn LZ77 algorithm with my friend, and some case give us a confusion.
for example)
init
- search buffer size: 7
- look-ahead buffer size: 8
- original string: abcabbcabbcabca
- current
window: abcabbc
view: abbcabca
What I thought the LLD tuple is :
Literal: 'a'
Length: 4
Distance: 4
What my friend thought the LLD tuple is :
Literal: 'c'
Length: 6
Distance: 4
I thought the algorithm to find longest match string only checks in search buffer, but he says there is no limit to find match string.
Who's answer is correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法给你一个明确的答案,但我可以证明 LZ77 没有理由不支持“过长”的元组。
我相信您在问元组的长度分量是否可以大于其距离分量。
换句话说,我相信您是在问将生成以下哪个元组流:
或
显然,后者会产生更好的压缩效果。
我无法给你一个明确的答案,但我可以证明解码器可以像编码器生成元组一样轻松地处理“过长”的元组。因此,LZ77 没有理由不支持他们。
重建第一个流的输入
简单。
重建第二个流的输入
(0,0,'a'): "" + "a" ⇒ "a"
(0,0,'b'): "" + "b" ⇒ "ab"
(0,0,'c'): "" + "c" ⇒ "abc"
(2,3,'b'): "ab" + "b" ⇒ "abcabb"
(7,4,'c')
到目前为止,我们已经生成了
abcabb
。该元组表示接下来的 7 个字符从abcabb
末尾的 4 个字符开始。我们缺少三个角色!我们是吗?如果都是一个缓冲区并且我们从左到右复制,我们就必须继续下去。
所以这不需要额外的努力就可以工作!
(7,4,'c'): "cabbcab" + "c" ⇒ "abcabbcabbcabc"
(0,0,'a'): "" + "a" ⇒ "abcabbcabbcabca"
I can't give you a definitive answer, but I can show there's no reason LZ77 couldn't support "overly long" tuples.
I believe you're asking if the length component of a tuple can be larger than its distance component.
In other words, I believe you're asking which of the following streams of tuples would be produced:
or
Obviously, the latter would produce better compression.
I can't give you a definitive answer, but I can show that the decoder can handle "overly long" tuples just as easily as the encoder can produce them. As such, there's no reason LZ77 couldn't support them.
Reconstructing the input from the first stream
Simple.
Reconstructing the input from the second stream
(0,0,'a'): "" + "a" ⇒ "a"
(0,0,'b'): "" + "b" ⇒ "ab"
(0,0,'c'): "" + "c" ⇒ "abc"
(2,3,'b'): "ab" + "b" ⇒ "abcabb"
(7,4,'c')
So far, we've produced
abcabb
. The tuple says the next 7 characters start 4 characters from the end ofabcabb
.We're missing three characters! Are are we? If it's all one buffer and we copy from left to right, we just have to keep going.
So this works with no extra effort!
(7,4,'c'): "cabbcab" + "c" ⇒ "abcabbcabbcabc"
(0,0,'a'): "" + "a" ⇒ "abcabbcabbcabca"
你的朋友是对的。一个简单的示例是,LZ77使用距离1匹配完成了运行长度编码,而长度为n-1 对于同一字节的 n 副本的运行。 (字节的第一次出现是字面意思。)
Your friend is right. A simpler example is that LZ77 accomplishes run-length coding with a distance 1 match, with length n-1 for a run of n copies of the same byte. (The first occurrence of the byte is a literal.)