Well, the so called ?Lazy Matching? or ?Lazy Evaluation? is a heuristic for more optimal LZ-coding. Obviously, if at each step we will grab the longest match, we may loose even longer match within the reach of a current match. Such thing called ?Greedy Parsing?. With the original ?Lazy Matching?, we delay the coding by one-step to see, is even longer match followed by the current match? If so, we drop a literal and this new even longer match. In addition to that, we may do a ?Lazy Matching? with a few bytes lookahead. This means that we delay the coding decision for a few, not just one step/byte.
Examples:
Code:
Greedy Parsing:
Len := GetMatchLen(CurPos);
// ..
if (Len >= MINMATCH)
Encode(Len);
// ..
Lazy Matching:
Len = GetMatchLen(CurPos);
if (Len >= MINMATCH) {
NextLen = GetMatchLen(CurPos + 1);
if (NextLen > Len)
Len = 0; // Drop current match
}
// ..
if (Len >= MINMATCH)
Encode(Len);
// ..
Lazy Matching with a few-byte lookahead:
Len = GetMatchLen(CurPos);
if (Len >= MINMATCH) {
for (i = 1; i <= LOOKAHEAD; i++) {
NextLen = GetMatchLen(CurPos + i);
if (NextLen >= (Len + i)) {
Len = 0; // Drop current match
break;
}
}
}
if (Len >= MINMATCH)
Encode(Len);
// ..
The ?Optimal Parsing? is more complicated. We getting ALL matches at EACH position. After, we try to build so called ?Optimal Path? or optimal sequence of literals and matches. Here are many variants on how we examine the cost or price of each choice, how we build/optimize path, etc.