Commit 396d6253 authored by Nigel Tao's avatar Nigel Tao

compress/lzw: fix comment re high-code invariant

The listed invariant, while technically true, was misleading, and the
invariant can be tightened. We never actually get to (d.hi ==
d.overflow), due to the "d.hi--" line in the decoder.decode method.

This is a comment-only commit, changing the comment to match the code.

A follow-up commit could restore the comment, changing the code to match
the original intented invariant. But the first step is to have the
comment and the code say the same thing.

Change-Id: Ifc9f78d5060454fc107af9be298026bf3043d400
Reviewed-on: https://go-review.googlesource.com/c/go/+/191358Reviewed-by: default avatarDaniel Martí <mvdan@mvdan.cc>
Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 3f0437e1
...@@ -63,8 +63,7 @@ type decoder struct { ...@@ -63,8 +63,7 @@ type decoder struct {
// //
// last is the most recently seen code, or decoderInvalidCode. // last is the most recently seen code, or decoderInvalidCode.
// //
// An invariant is that // An invariant is that hi < overflow.
// (hi < overflow) || (hi == overflow && last == decoderInvalidCode)
clear, eof, hi, overflow, last uint16 clear, eof, hi, overflow, last uint16
// Each code c in [lo, hi] expands to two or more bytes. For c != hi: // Each code c in [lo, hi] expands to two or more bytes. For c != hi:
...@@ -203,7 +202,7 @@ loop: ...@@ -203,7 +202,7 @@ loop:
if d.width == maxWidth { if d.width == maxWidth {
d.last = decoderInvalidCode d.last = decoderInvalidCode
// Undo the d.hi++ a few lines above, so that (1) we maintain // Undo the d.hi++ a few lines above, so that (1) we maintain
// the invariant that d.hi <= d.overflow, and (2) d.hi does not // the invariant that d.hi < d.overflow, and (2) d.hi does not
// eventually overflow a uint16. // eventually overflow a uint16.
d.hi-- d.hi--
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment