1 /* LzFind.c -- Match finder for LZ algorithms
\r
2 2015-10-15 : Igor Pavlov : Public domain */
\r
11 #define kEmptyHashValue 0
\r
12 #define kMaxValForNormalize ((UInt32)0xFFFFFFFF)
\r
13 #define kNormalizeStepMin (1 << 10) /* it must be power of 2 */
\r
14 #define kNormalizeMask (~(UInt32)(kNormalizeStepMin - 1))
\r
15 #define kMaxHistorySize ((UInt32)7 << 29)
\r
17 #define kStartMaxLen 3
\r
19 static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
\r
21 if (!p->directInput)
\r
23 alloc->Free(alloc, p->bufferBase);
\r
24 p->bufferBase = NULL;
\r
28 /* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */
\r
30 static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
\r
32 UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
\r
35 p->blockSize = blockSize;
\r
38 if (!p->bufferBase || p->blockSize != blockSize)
\r
40 LzInWindow_Free(p, alloc);
\r
41 p->blockSize = blockSize;
\r
42 p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);
\r
44 return (p->bufferBase != NULL);
\r
47 Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
\r
49 UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
\r
51 void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
\r
53 p->posLimit -= subValue;
\r
55 p->streamPos -= subValue;
\r
58 static void MatchFinder_ReadBlock(CMatchFinder *p)
\r
60 if (p->streamEndWasReached || p->result != SZ_OK)
\r
63 /* We use (p->streamPos - p->pos) value. (p->streamPos < p->pos) is allowed. */
\r
67 UInt32 curSize = 0xFFFFFFFF - (p->streamPos - p->pos);
\r
68 if (curSize > p->directInputRem)
\r
69 curSize = (UInt32)p->directInputRem;
\r
70 p->directInputRem -= curSize;
\r
71 p->streamPos += curSize;
\r
72 if (p->directInputRem == 0)
\r
73 p->streamEndWasReached = 1;
\r
79 Byte *dest = p->buffer + (p->streamPos - p->pos);
\r
80 size_t size = (p->bufferBase + p->blockSize - dest);
\r
84 p->result = p->stream->Read(p->stream, dest, &size);
\r
85 if (p->result != SZ_OK)
\r
89 p->streamEndWasReached = 1;
\r
92 p->streamPos += (UInt32)size;
\r
93 if (p->streamPos - p->pos > p->keepSizeAfter)
\r
98 void MatchFinder_MoveBlock(CMatchFinder *p)
\r
100 memmove(p->bufferBase,
\r
101 p->buffer - p->keepSizeBefore,
\r
102 (size_t)(p->streamPos - p->pos) + p->keepSizeBefore);
\r
103 p->buffer = p->bufferBase + p->keepSizeBefore;
\r
106 int MatchFinder_NeedMove(CMatchFinder *p)
\r
108 if (p->directInput)
\r
110 /* if (p->streamEndWasReached) return 0; */
\r
111 return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
\r
114 void MatchFinder_ReadIfRequired(CMatchFinder *p)
\r
116 if (p->streamEndWasReached)
\r
118 if (p->keepSizeAfter >= p->streamPos - p->pos)
\r
119 MatchFinder_ReadBlock(p);
\r
122 static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
\r
124 if (MatchFinder_NeedMove(p))
\r
125 MatchFinder_MoveBlock(p);
\r
126 MatchFinder_ReadBlock(p);
\r
129 static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
\r
133 p->numHashBytes = 4;
\r
137 #define kCrcPoly 0xEDB88320
\r
139 void MatchFinder_Construct(CMatchFinder *p)
\r
142 p->bufferBase = NULL;
\r
143 p->directInput = 0;
\r
145 MatchFinder_SetDefaultSettings(p);
\r
147 for (i = 0; i < 256; i++)
\r
151 for (j = 0; j < 8; j++)
\r
152 r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
\r
157 static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)
\r
159 alloc->Free(alloc, p->hash);
\r
163 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)
\r
165 MatchFinder_FreeThisClassMemory(p, alloc);
\r
166 LzInWindow_Free(p, alloc);
\r
169 static CLzRef* AllocRefs(size_t num, ISzAlloc *alloc)
\r
171 size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
\r
172 if (sizeInBytes / sizeof(CLzRef) != num)
\r
174 return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);
\r
177 int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
\r
178 UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
\r
183 if (historySize > kMaxHistorySize)
\r
185 MatchFinder_Free(p, alloc);
\r
189 sizeReserv = historySize >> 1;
\r
190 if (historySize >= ((UInt32)3 << 30)) sizeReserv = historySize >> 3;
\r
191 else if (historySize >= ((UInt32)2 << 30)) sizeReserv = historySize >> 2;
\r
193 sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);
\r
195 p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
\r
196 p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;
\r
198 /* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */
\r
200 if (LzInWindow_Create(p, sizeReserv, alloc))
\r
202 UInt32 newCyclicBufferSize = historySize + 1;
\r
204 p->matchMaxLen = matchMaxLen;
\r
206 p->fixedHashSize = 0;
\r
207 if (p->numHashBytes == 2)
\r
208 hs = (1 << 16) - 1;
\r
211 hs = historySize - 1;
\r
217 hs |= 0xFFFF; /* don't change it! It's required for Deflate */
\r
218 if (hs > (1 << 24))
\r
220 if (p->numHashBytes == 3)
\r
221 hs = (1 << 24) - 1;
\r
224 /* if (bigHash) mode, GetHeads4b() in LzFindMt.c needs (hs >= ((1 << 24) - 1))) */
\r
229 if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;
\r
230 if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;
\r
231 if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;
\r
232 hs += p->fixedHashSize;
\r
238 p->historySize = historySize;
\r
239 p->hashSizeSum = hs;
\r
240 p->cyclicBufferSize = newCyclicBufferSize;
\r
242 numSons = newCyclicBufferSize;
\r
245 newSize = hs + numSons;
\r
247 if (p->hash && p->numRefs == newSize)
\r
250 MatchFinder_FreeThisClassMemory(p, alloc);
\r
251 p->numRefs = newSize;
\r
252 p->hash = AllocRefs(newSize, alloc);
\r
256 p->son = p->hash + p->hashSizeSum;
\r
262 MatchFinder_Free(p, alloc);
\r
266 static void MatchFinder_SetLimits(CMatchFinder *p)
\r
268 UInt32 limit = kMaxValForNormalize - p->pos;
\r
269 UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
\r
271 if (limit2 < limit)
\r
273 limit2 = p->streamPos - p->pos;
\r
275 if (limit2 <= p->keepSizeAfter)
\r
281 limit2 -= p->keepSizeAfter;
\r
283 if (limit2 < limit)
\r
287 UInt32 lenLimit = p->streamPos - p->pos;
\r
288 if (lenLimit > p->matchMaxLen)
\r
289 lenLimit = p->matchMaxLen;
\r
290 p->lenLimit = lenLimit;
\r
292 p->posLimit = p->pos + limit;
\r
295 void MatchFinder_Init_2(CMatchFinder *p, int readData)
\r
298 UInt32 *hash = p->hash;
\r
299 UInt32 num = p->hashSizeSum;
\r
300 for (i = 0; i < num; i++)
\r
301 hash[i] = kEmptyHashValue;
\r
303 p->cyclicBufferPos = 0;
\r
304 p->buffer = p->bufferBase;
\r
305 p->pos = p->streamPos = p->cyclicBufferSize;
\r
307 p->streamEndWasReached = 0;
\r
310 MatchFinder_ReadBlock(p);
\r
312 MatchFinder_SetLimits(p);
\r
315 void MatchFinder_Init(CMatchFinder *p)
\r
317 MatchFinder_Init_2(p, True);
\r
320 static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
\r
322 return (p->pos - p->historySize - 1) & kNormalizeMask;
\r
325 void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems)
\r
328 for (i = 0; i < numItems; i++)
\r
330 UInt32 value = items[i];
\r
331 if (value <= subValue)
\r
332 value = kEmptyHashValue;
\r
339 static void MatchFinder_Normalize(CMatchFinder *p)
\r
341 UInt32 subValue = MatchFinder_GetSubValue(p);
\r
342 MatchFinder_Normalize3(subValue, p->hash, p->numRefs);
\r
343 MatchFinder_ReduceOffsets(p, subValue);
\r
346 static void MatchFinder_CheckLimits(CMatchFinder *p)
\r
348 if (p->pos == kMaxValForNormalize)
\r
349 MatchFinder_Normalize(p);
\r
350 if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)
\r
351 MatchFinder_CheckAndMoveAndRead(p);
\r
352 if (p->cyclicBufferPos == p->cyclicBufferSize)
\r
353 p->cyclicBufferPos = 0;
\r
354 MatchFinder_SetLimits(p);
\r
357 static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
\r
358 UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
\r
359 UInt32 *distances, UInt32 maxLen)
\r
361 son[_cyclicBufferPos] = curMatch;
\r
364 UInt32 delta = pos - curMatch;
\r
365 if (cutValue-- == 0 || delta >= _cyclicBufferSize)
\r
368 const Byte *pb = cur - delta;
\r
369 curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
\r
370 if (pb[maxLen] == cur[maxLen] && *pb == *cur)
\r
373 while (++len != lenLimit)
\r
374 if (pb[len] != cur[len])
\r
378 *distances++ = maxLen = len;
\r
379 *distances++ = delta - 1;
\r
380 if (len == lenLimit)
\r
388 UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
\r
389 UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
\r
390 UInt32 *distances, UInt32 maxLen)
\r
392 CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
\r
393 CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
\r
394 UInt32 len0 = 0, len1 = 0;
\r
397 UInt32 delta = pos - curMatch;
\r
398 if (cutValue-- == 0 || delta >= _cyclicBufferSize)
\r
400 *ptr0 = *ptr1 = kEmptyHashValue;
\r
404 CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
\r
405 const Byte *pb = cur - delta;
\r
406 UInt32 len = (len0 < len1 ? len0 : len1);
\r
407 if (pb[len] == cur[len])
\r
409 if (++len != lenLimit && pb[len] == cur[len])
\r
410 while (++len != lenLimit)
\r
411 if (pb[len] != cur[len])
\r
415 *distances++ = maxLen = len;
\r
416 *distances++ = delta - 1;
\r
417 if (len == lenLimit)
\r
425 if (pb[len] < cur[len])
\r
443 static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
\r
444 UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)
\r
446 CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
\r
447 CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
\r
448 UInt32 len0 = 0, len1 = 0;
\r
451 UInt32 delta = pos - curMatch;
\r
452 if (cutValue-- == 0 || delta >= _cyclicBufferSize)
\r
454 *ptr0 = *ptr1 = kEmptyHashValue;
\r
458 CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
\r
459 const Byte *pb = cur - delta;
\r
460 UInt32 len = (len0 < len1 ? len0 : len1);
\r
461 if (pb[len] == cur[len])
\r
463 while (++len != lenLimit)
\r
464 if (pb[len] != cur[len])
\r
467 if (len == lenLimit)
\r
475 if (pb[len] < cur[len])
\r
494 ++p->cyclicBufferPos; \
\r
496 if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
\r
498 #define MOVE_POS_RET MOVE_POS return offset;
\r
500 static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
\r
502 #define GET_MATCHES_HEADER2(minLen, ret_op) \
\r
503 UInt32 lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \
\r
504 lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
\r
507 #define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)
\r
508 #define SKIP_HEADER(minLen) GET_MATCHES_HEADER2(minLen, continue)
\r
510 #define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
\r
512 #define GET_MATCHES_FOOTER(offset, maxLen) \
\r
513 offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \
\r
514 distances + offset, maxLen) - distances); MOVE_POS_RET;
\r
516 #define SKIP_FOOTER \
\r
517 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
\r
519 #define UPDATE_maxLen { \
\r
520 ptrdiff_t diff = (ptrdiff_t)0 - d2; \
\r
521 const Byte *c = cur + maxLen; \
\r
522 const Byte *lim = cur + lenLimit; \
\r
523 for (; c != lim; c++) if (*(c + diff) != *c) break; \
\r
524 maxLen = (UInt32)(c - cur); }
\r
526 static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
\r
529 GET_MATCHES_HEADER(2)
\r
531 curMatch = p->hash[hv];
\r
532 p->hash[hv] = p->pos;
\r
534 GET_MATCHES_FOOTER(offset, 1)
\r
537 UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
\r
540 GET_MATCHES_HEADER(3)
\r
542 curMatch = p->hash[hv];
\r
543 p->hash[hv] = p->pos;
\r
545 GET_MATCHES_FOOTER(offset, 2)
\r
548 static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
\r
550 UInt32 h2, d2, maxLen, offset, pos;
\r
552 GET_MATCHES_HEADER(3)
\r
559 d2 = pos - hash[h2];
\r
561 curMatch = hash[kFix3HashSize + hv];
\r
564 hash[kFix3HashSize + hv] = pos;
\r
569 if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
\r
572 distances[0] = maxLen;
\r
573 distances[1] = d2 - 1;
\r
575 if (maxLen == lenLimit)
\r
577 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
\r
582 GET_MATCHES_FOOTER(offset, maxLen)
\r
585 static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
\r
587 UInt32 h2, h3, d2, d3, maxLen, offset, pos;
\r
589 GET_MATCHES_HEADER(4)
\r
596 d2 = pos - hash[ h2];
\r
597 d3 = pos - hash[kFix3HashSize + h3];
\r
599 curMatch = hash[kFix4HashSize + hv];
\r
602 hash[kFix3HashSize + h3] = pos;
\r
603 hash[kFix4HashSize + hv] = pos;
\r
608 if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
\r
610 distances[0] = maxLen = 2;
\r
611 distances[1] = d2 - 1;
\r
615 if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
\r
618 distances[offset + 1] = d3 - 1;
\r
626 distances[offset - 2] = maxLen;
\r
627 if (maxLen == lenLimit)
\r
629 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
\r
637 GET_MATCHES_FOOTER(offset, maxLen)
\r
641 static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
\r
643 UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos;
\r
645 GET_MATCHES_HEADER(5)
\r
652 d2 = pos - hash[ h2];
\r
653 d3 = pos - hash[kFix3HashSize + h3];
\r
654 d4 = pos - hash[kFix4HashSize + h4];
\r
656 curMatch = hash[kFix5HashSize + hv];
\r
659 hash[kFix3HashSize + h3] = pos;
\r
660 hash[kFix4HashSize + h4] = pos;
\r
661 hash[kFix5HashSize + hv] = pos;
\r
666 if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
\r
668 distances[0] = maxLen = 2;
\r
669 distances[1] = d2 - 1;
\r
671 if (*(cur - d2 + 2) == cur[2])
\r
672 distances[0] = maxLen = 3;
\r
673 else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
\r
675 distances[2] = maxLen = 3;
\r
676 distances[3] = d3 - 1;
\r
681 else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
\r
683 distances[0] = maxLen = 3;
\r
684 distances[1] = d3 - 1;
\r
689 if (d2 != d4 && d4 < p->cyclicBufferSize
\r
690 && *(cur - d4) == *cur
\r
691 && *(cur - d4 + 3) == *(cur + 3))
\r
694 distances[offset + 1] = d4 - 1;
\r
702 distances[offset - 2] = maxLen;
\r
703 if (maxLen == lenLimit)
\r
705 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
\r
713 GET_MATCHES_FOOTER(offset, maxLen)
\r
717 static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
\r
719 UInt32 h2, h3, d2, d3, maxLen, offset, pos;
\r
721 GET_MATCHES_HEADER(4)
\r
728 d2 = pos - hash[ h2];
\r
729 d3 = pos - hash[kFix3HashSize + h3];
\r
731 curMatch = hash[kFix4HashSize + hv];
\r
734 hash[kFix3HashSize + h3] = pos;
\r
735 hash[kFix4HashSize + hv] = pos;
\r
740 if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
\r
742 distances[0] = maxLen = 2;
\r
743 distances[1] = d2 - 1;
\r
747 if (d2 != d3 && d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
\r
750 distances[offset + 1] = d3 - 1;
\r
758 distances[offset - 2] = maxLen;
\r
759 if (maxLen == lenLimit)
\r
761 p->son[p->cyclicBufferPos] = curMatch;
\r
769 offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
\r
770 distances + offset, maxLen) - (distances));
\r
775 static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
\r
777 UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos
\r
779 GET_MATCHES_HEADER(5)
\r
786 d2 = pos - hash[ h2];
\r
787 d3 = pos - hash[kFix3HashSize + h3];
\r
788 d4 = pos - hash[kFix4HashSize + h4];
\r
790 curMatch = hash[kFix5HashSize + hv];
\r
793 hash[kFix3HashSize + h3] = pos;
\r
794 hash[kFix4HashSize + h4] = pos;
\r
795 hash[kFix5HashSize + hv] = pos;
\r
800 if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur)
\r
802 distances[0] = maxLen = 2;
\r
803 distances[1] = d2 - 1;
\r
805 if (*(cur - d2 + 2) == cur[2])
\r
806 distances[0] = maxLen = 3;
\r
807 else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
\r
809 distances[2] = maxLen = 3;
\r
810 distances[3] = d3 - 1;
\r
815 else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur)
\r
817 distances[0] = maxLen = 3;
\r
818 distances[1] = d3 - 1;
\r
823 if (d2 != d4 && d4 < p->cyclicBufferSize
\r
824 && *(cur - d4) == *cur
\r
825 && *(cur - d4 + 3) == *(cur + 3))
\r
828 distances[offset + 1] = d4 - 1;
\r
836 distances[offset - 2] = maxLen;
\r
837 if (maxLen == lenLimit)
\r
839 p->son[p->cyclicBufferPos] = curMatch;
\r
847 offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
\r
848 distances + offset, maxLen) - (distances));
\r
853 UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
\r
856 GET_MATCHES_HEADER(3)
\r
858 curMatch = p->hash[hv];
\r
859 p->hash[hv] = p->pos;
\r
860 offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
\r
861 distances, 2) - (distances));
\r
865 static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
\r
871 curMatch = p->hash[hv];
\r
872 p->hash[hv] = p->pos;
\r
875 while (--num != 0);
\r
878 void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
\r
884 curMatch = p->hash[hv];
\r
885 p->hash[hv] = p->pos;
\r
888 while (--num != 0);
\r
891 static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
\r
900 curMatch = hash[kFix3HashSize + hv];
\r
902 hash[kFix3HashSize + hv] = p->pos;
\r
905 while (--num != 0);
\r
908 static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
\r
917 curMatch = hash[kFix4HashSize + hv];
\r
919 hash[kFix3HashSize + h3] =
\r
920 hash[kFix4HashSize + hv] = p->pos;
\r
923 while (--num != 0);
\r
927 static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
\r
936 curMatch = hash[kFix5HashSize + hv];
\r
938 hash[kFix3HashSize + h3] =
\r
939 hash[kFix4HashSize + h4] =
\r
940 hash[kFix5HashSize + hv] = p->pos;
\r
943 while (--num != 0);
\r
947 static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
\r
956 curMatch = hash[kFix4HashSize + hv];
\r
958 hash[kFix3HashSize + h3] =
\r
959 hash[kFix4HashSize + hv] = p->pos;
\r
960 p->son[p->cyclicBufferPos] = curMatch;
\r
963 while (--num != 0);
\r
967 static void Hc5_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
\r
976 curMatch = p->hash[kFix5HashSize + hv];
\r
978 hash[kFix3HashSize + h3] =
\r
979 hash[kFix4HashSize + h4] =
\r
980 hash[kFix5HashSize + hv] = p->pos;
\r
981 p->son[p->cyclicBufferPos] = curMatch;
\r
984 while (--num != 0);
\r
988 void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
\r
994 curMatch = p->hash[hv];
\r
995 p->hash[hv] = p->pos;
\r
996 p->son[p->cyclicBufferPos] = curMatch;
\r
999 while (--num != 0);
\r
1002 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
\r
1004 vTable->Init = (Mf_Init_Func)MatchFinder_Init;
\r
1005 vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;
\r
1006 vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;
\r
1009 /* if (p->numHashBytes <= 4) */
\r
1011 vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
\r
1012 vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
\r
1017 vTable->GetMatches = (Mf_GetMatches_Func)Hc5_MatchFinder_GetMatches;
\r
1018 vTable->Skip = (Mf_Skip_Func)Hc5_MatchFinder_Skip;
\r
1022 else if (p->numHashBytes == 2)
\r
1024 vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;
\r
1025 vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
\r
1027 else if (p->numHashBytes == 3)
\r
1029 vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
\r
1030 vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
\r
1032 else /* if (p->numHashBytes == 4) */
\r
1034 vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
\r
1035 vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
\r
1040 vTable->GetMatches = (Mf_GetMatches_Func)Bt5_MatchFinder_GetMatches;
\r
1041 vTable->Skip = (Mf_Skip_Func)Bt5_MatchFinder_Skip;
\r