Lines Matching defs:p
22 static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
24 if (!p->directInput)
26 alloc->Free(alloc, p->bufferBase, 0);
27 p->bufferBase = 0;
33 static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
35 UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
36 if (p->directInput)
38 p->blockSize = blockSize;
41 if (p->bufferBase == 0 || p->blockSize != blockSize)
43 LzInWindow_Free(p, alloc);
44 p->blockSize = blockSize;
45 p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);
47 return (p->bufferBase != 0);
50 Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
51 Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
53 UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
55 void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
57 p->posLimit -= subValue;
58 p->pos -= subValue;
59 p->streamPos -= subValue;
62 static void MatchFinder_ReadBlock(CMatchFinder *p)
64 if (p->streamEndWasReached || p->result != SZ_OK)
68 Byte *dest = p->buffer + (p->streamPos - p->pos);
69 size_t size = (p->bufferBase + p->blockSize - dest);
72 p->result = p->stream->Read(p->stream, dest, &size);
73 if (p->result != SZ_OK)
77 p->streamEndWasReached = 1;
80 p->streamPos += (UInt32)size;
81 if (p->streamPos - p->pos > p->keepSizeAfter)
86 void MatchFinder_MoveBlock(CMatchFinder *p)
88 memmove(p->bufferBase,
89 p->buffer - p->keepSizeBefore,
90 (size_t)(p->streamPos - p->pos + p->keepSizeBefore));
91 p->buffer = p->bufferBase + p->keepSizeBefore;
94 int MatchFinder_NeedMove(CMatchFinder *p)
96 /* if (p->streamEndWasReached) return 0; */
97 return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
100 void MatchFinder_ReadIfRequired(CMatchFinder *p)
102 if (p->streamEndWasReached)
104 if (p->keepSizeAfter >= p->streamPos - p->pos)
105 MatchFinder_ReadBlock(p);
108 static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
110 if (MatchFinder_NeedMove(p))
111 MatchFinder_MoveBlock(p);
112 MatchFinder_ReadBlock(p);
115 static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
117 p->cutValue = 32;
118 p->btMode = 1;
119 p->numHashBytes = 4;
120 /* p->skipModeBits = 0; */
121 p->directInput = 0;
122 p->bigHash = 0;
127 void MatchFinder_Construct(CMatchFinder *p)
130 p->bufferBase = 0;
131 p->directInput = 0;
132 p->hash = 0;
133 MatchFinder_SetDefaultSettings(p);
141 p->crc[i] = r;
145 static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)
147 alloc->Free(alloc, p->hash, 0);
148 p->hash = 0;
151 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)
153 MatchFinder_FreeThisClassMemory(p, alloc);
154 LzInWindow_Free(p, alloc);
165 int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
172 MatchFinder_Free(p, alloc);
180 p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
181 p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;
183 if (LzInWindow_Create(p, sizeReserv, alloc))
185 UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;
187 p->matchMaxLen = matchMaxLen;
189 p->fixedHashSize = 0;
190 if (p->numHashBytes == 2)
200 /* hs >>= p->skipModeBits; */
204 if (p->numHashBytes == 3)
210 p->hashMask = hs;
212 if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;
213 if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;
214 if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;
215 hs += p->fixedHashSize;
219 UInt32 prevSize = p->hashSizeSum + p->numSons;
221 p->historySize = historySize;
222 p->hashSizeSum = hs;
223 p->cyclicBufferSize = newCyclicBufferSize;
224 p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);
225 newSize = p->hashSizeSum + p->numSons;
226 if (p->hash != 0 && prevSize == newSize)
228 MatchFinder_FreeThisClassMemory(p, alloc);
229 p->hash = AllocRefs(newSize, alloc);
230 if (p->hash != 0)
232 p->son = p->hash + p->hashSizeSum;
237 MatchFinder_Free(p, alloc);
241 static void MatchFinder_SetLimits(CMatchFinder *p)
243 UInt32 limit = kMaxValForNormalize - p->pos;
244 UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
247 limit2 = p->streamPos - p->pos;
248 if (limit2 <= p->keepSizeAfter)
254 limit2 -= p->keepSizeAfter;
258 UInt32 lenLimit = p->streamPos - p->pos;
259 if (lenLimit > p->matchMaxLen)
260 lenLimit = p->matchMaxLen;
261 p->lenLimit = lenLimit;
263 p->posLimit = p->pos + limit;
266 void MatchFinder_Init(CMatchFinder *p)
269 for (i = 0; i < p->hashSizeSum; i++)
270 p->hash[i] = kEmptyHashValue;
271 p->cyclicBufferPos = 0;
272 p->buffer = p->bufferBase;
273 p->pos = p->streamPos = p->cyclicBufferSize;
274 p->result = SZ_OK;
275 p->streamEndWasReached = 0;
276 MatchFinder_ReadBlock(p);
277 MatchFinder_SetLimits(p);
280 static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
282 return (p->pos - p->historySize - 1) & kNormalizeMask;
299 static void MatchFinder_Normalize(CMatchFinder *p)
301 UInt32 subValue = MatchFinder_GetSubValue(p);
302 MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);
303 MatchFinder_ReduceOffsets(p, subValue);
306 static void MatchFinder_CheckLimits(CMatchFinder *p)
308 if (p->pos == kMaxValForNormalize)
309 MatchFinder_Normalize(p);
310 if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)
311 MatchFinder_CheckAndMoveAndRead(p);
312 if (p->cyclicBufferPos == p->cyclicBufferSize)
313 p->cyclicBufferPos = 0;
314 MatchFinder_SetLimits(p);
454 ++p->cyclicBufferPos; \
455 p->buffer++; \
456 if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
460 static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
464 lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
465 cur = p->buffer;
470 #define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
473 offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \
477 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
479 static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
484 curMatch = p->hash[hashValue];
485 p->hash[hashValue] = p->pos;
490 UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
495 curMatch = p->hash[hashValue];
496 p->hash[hashValue] = p->pos;
501 static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
508 delta2 = p->pos - p->hash[hash2Value];
509 curMatch = p->hash[kFix3HashSize + hashValue];
511 p->hash[hash2Value] =
512 p->hash[kFix3HashSize + hashValue] = p->pos;
517 if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
527 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
534 static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
541 delta2 = p->pos - p->hash[ hash2Value];
542 delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
543 curMatch = p->hash[kFix4HashSize + hashValue];
545 p->hash[ hash2Value] =
546 p->hash[kFix3HashSize + hash3Value] =
547 p->hash[kFix4HashSize + hashValue] = p->pos;
551 if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
557 if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
572 SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
581 static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
588 delta2 = p->pos - p->hash[ hash2Value];
589 delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
590 curMatch = p->hash[kFix4HashSize + hashValue];
592 p->hash[ hash2Value] =
593 p->hash[kFix3HashSize + hash3Value] =
594 p->hash[kFix4HashSize + hashValue] = p->pos;
598 if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
604 if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
619 p->son[p->cyclicBufferPos] = curMatch;
625 offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
630 UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
635 curMatch = p->hash[hashValue];
636 p->hash[hashValue] = p->pos;
637 offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
642 static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
648 curMatch = p->hash[hashValue];
649 p->hash[hashValue] = p->pos;
655 void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
661 curMatch = p->hash[hashValue];
662 p->hash[hashValue] = p->pos;
668 static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
675 curMatch = p->hash[kFix3HashSize + hashValue];
676 p->hash[hash2Value] =
677 p->hash[kFix3HashSize + hashValue] = p->pos;
683 static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
690 curMatch = p->hash[kFix4HashSize + hashValue];
691 p->hash[ hash2Value] =
692 p->hash[kFix3HashSize + hash3Value] = p->pos;
693 p->hash[kFix4HashSize + hashValue] = p->pos;
699 static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
706 curMatch = p->hash[kFix4HashSize + hashValue];
707 p->hash[ hash2Value] =
708 p->hash[kFix3HashSize + hash3Value] =
709 p->hash[kFix4HashSize + hashValue] = p->pos;
710 p->son[p->cyclicBufferPos] = curMatch;
716 void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
722 curMatch = p->hash[hashValue];
723 p->hash[hashValue] = p->pos;
724 p->son[p->cyclicBufferPos] = curMatch;
730 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
736 if (!p->btMode)
741 else if (p->numHashBytes == 2)
746 else if (p->numHashBytes == 3)