Predict an overlapping copy
Output currently AB. Next token is distance=2, length=5.
Can the decoder take five bytes from the old output?
1 / 5
Output currently AB. Next token is distance=2, length=5.
Can the decoder take five bytes from the old output?
AB → ABA → ABAB → ABABA → ABABAB → ABABABA.
Recompute len(output)-2 for every append. Newly produced bytes become valid sources.
Longest match wins, then smallest distance; length below three becomes a literal.
Encode ABABABA from the 256-byte dictionary.
Emit 65, add 256=AB. Emit 66, add 257=BA. Emit 256, add 258=ABA. Emit 258 at end.
The decoder has previous=AB and nextCode=258 when it receives 258.
Its next entry must be previous+first(previous)=ABA.
The exception permits exactly nextCode, not arbitrary unknown codes.
Decode [90,256]: Z followed by ZZ produces ZZZ.
At size 4096 both dictionaries stop adding. No implicit reset.
Integer code output does not specify variable-width bit packing or a GIF file.