internal void BtFillBlock(uint globalBlockIndex) { CMtSync sync = mHashSync; if (!sync.mNeedStart) { CriticalSection_Enter(sync.mCS); sync.mCsWasEntered = true; } BtGetMatches(mBtBuf + (globalBlockIndex & kMtBtNumBlocksMask) * kMtBtBlockSize); if (mLocalPos > kMtMaxValForNormalize - kMtBtBlockSize) { uint subValue = mLocalPos - mLocalCyclicBufferSize; CMatchFinder.MatchFinder_Normalize3(subValue, mLocalSon, mLocalCyclicBufferSize * 2); mLocalPos -= subValue; } if (!sync.mNeedStart) { CriticalSection_Leave(sync.mCS); sync.mCsWasEntered = false; } }
internal static void MatchFinder_CreateVTable(CMatchFinder p, out IMatchFinder vTable) { TR("MatchFinder_CreateVTable", p.mNumHashBytes); if (!p.mBtMode) vTable = new MatchFinderHc4(); else if (p.mNumHashBytes == 2) vTable = new MatchFinderBt2(); else if (p.mNumHashBytes == 3) vTable = new MatchFinderBt3(); else vTable = new MatchFinderBt4(); }
internal static void MatchFinder_CreateVTable(CMatchFinder p, out IMatchFinder vTable) { //TR("MatchFinder_CreateVTable", p.mNumHashBytes); if (!p.mBtMode) { vTable = new MatchFinderHc4(); } else if (p.mNumHashBytes == 2) { vTable = new MatchFinderBt2(); } else if (p.mNumHashBytes == 3) { vTable = new MatchFinderBt3(); } else { vTable = new MatchFinderBt4(); } }
/* Call it after ReleaseStream / SetStream */ private static void MatchFinderMt_Init(CMatchFinderMt p) { CMatchFinder mf = p; p.mBtBufPos = p.mBtBufPosLimit = 0; p.mHashBufPos = p.mHashBufPosLimit = 0; mf.MatchFinder_Init(); p.mPointerToCurPos = mf.MatchFinder_GetPointerToCurrentPos(); p.mBtNumAvailBytes = 0; p.mLzPos = p.mLocalHistorySize + 1; p.mLocalHash = mf.mHash; p.mLocalFixedHashSize = mf.mFixedHashSize; p.mLocalSon = mf.mSon; p.mLocalMatchMaxLen = mf.mMatchMaxLen; p.mLocalNumHashBytes = mf.mNumHashBytes; p.mLocalPos = mf.mPos; p.mLocalBuffer = mf.mBuffer; p.mLocalCyclicBufferPos = mf.mCyclicBufferPos; p.mLocalCyclicBufferSize = mf.mCyclicBufferSize; p.mLocalCutValue = mf.mCutValue; }
internal CLzmaEnc() // LzmaEnc_Construct { mRC.RangeEnc_Construct(); #if !_7ZIP_ST mMatchFinderMt = new CMatchFinderMt(); mMatchFinderBase = mMatchFinderMt; #else mMatchFinderBase = new CMatchFinder(); #endif LzmaEnc_SetProps(CLzmaEncProps.LzmaEncProps_Init()); LzmaEnc_FastPosInit(); LzmaEnc_InitPriceTables(mProbPrices); mLitProbs = null; mSaveState.mLitProbs = null; }
internal void BtGetMatches(P <uint> distances) { uint numProcessed = 0; uint curPos = 2; uint limit = kMtBtBlockSize - (mLocalMatchMaxLen * 2); distances[1] = mHashNumAvail; while (curPos < limit) { if (mHashBufPos == mHashBufPosLimit) { MatchFinderMt_GetNextBlock_Hash(); distances[1] = numProcessed + mHashNumAvail; if (mHashNumAvail >= mLocalNumHashBytes) { continue; } while (mHashNumAvail != 0) { distances[curPos++] = 0; mHashNumAvail--; } break; } { TR("BtGetMatches:cyclicBufferPos0", mLocalCyclicBufferPos); uint size = mHashBufPosLimit - mHashBufPos; uint lenLimit = mLocalMatchMaxLen; uint pos = mLocalPos; uint cyclicBufferPos = mLocalCyclicBufferPos; if (lenLimit >= mHashNumAvail) { lenLimit = mHashNumAvail; } { uint size2 = mHashNumAvail - lenLimit + 1; if (size2 < size) { size = size2; } size2 = mLocalCyclicBufferSize - cyclicBufferPos; if (size2 < size) { size = size2; } } while (curPos < limit && size-- != 0) { P <uint> startDistances = distances + curPos; uint num = (uint)(CMatchFinder.GetMatchesSpec1(lenLimit, pos - mHashBuf[mHashBufPos++], pos, mLocalBuffer, mLocalSon, cyclicBufferPos, mLocalCyclicBufferSize, mLocalCutValue, startDistances + 1, mLocalNumHashBytes - 1) - startDistances); TR("GetMatchesSpec1", num); startDistances[0] = num - 1; curPos += num; cyclicBufferPos++; pos++; mLocalBuffer++; } numProcessed += pos - mLocalPos; mHashNumAvail -= pos - mLocalPos; mLocalPos = pos; if (cyclicBufferPos == mLocalCyclicBufferSize) { cyclicBufferPos = 0; } mLocalCyclicBufferPos = cyclicBufferPos; TR("BtGetMatches:cyclicBufferPos1", mLocalCyclicBufferPos); } } distances[0] = curPos; }
internal void HashThreadFunc() { CMtSync p = mHashSync; for (;;) { uint numProcessedBlocks = 0; Event_Wait(p.mCanStart); Event_Set(p.mWasStarted); for (;;) { if (p.mExit) { return; } Trace.MatchObjectWait(p, "HashThreadFunc:stop"); if (p.mStopWriting) { Trace.MatchObjectWait(p, "HashThreadFunc:stop"); p.mNumProcessedBlocks = numProcessedBlocks; Event_Set(p.mWasStopped); break; } Trace.MatchObjectWait(p, "HashThreadFunc:stop"); if (base.MatchFinder_NeedMove()) { CriticalSection_Enter(mBtSync.mCS); CriticalSection_Enter(mHashSync.mCS); { P <byte> beforePtr = base.MatchFinder_GetPointerToCurrentPos(); base.MatchFinder_MoveBlock(); P <byte> afterPtr = base.MatchFinder_GetPointerToCurrentPos(); mPointerToCurPos -= beforePtr - afterPtr; mLocalBuffer -= beforePtr - afterPtr; } CriticalSection_Leave(mBtSync.mCS); CriticalSection_Leave(mHashSync.mCS); continue; } Semaphore_Wait(p.mFreeSemaphore); base.MatchFinder_ReadIfRequired(); if (base.mPos > (kMtMaxValForNormalize - kMtHashBlockSize)) { uint subValue = (base.mPos - base.mHistorySize - 1); base.MatchFinder_ReduceOffsets(subValue); CMatchFinder.MatchFinder_Normalize3(subValue, P.From(base.mHash, base.mFixedHashSize), base.mHashMask + 1); } P <uint> heads = P.From(mHashBuf, ((numProcessedBlocks++) & kMtHashNumBlocksMask) * kMtHashBlockSize); uint num = base.mStreamPos - base.mPos; heads[0] = 2; heads[1] = num; if (num >= base.mNumHashBytes) { num = num - base.mNumHashBytes + 1; if (num > kMtHashBlockSize - 2) { num = kMtHashBlockSize - 2; } mInterface.GetHeadsFunc(base.mBuffer, base.mPos, P.From(base.mHash, base.mFixedHashSize), base.mHashMask, heads + 2, num); heads[0] += num; } base.mPos += num; base.mBuffer += num; Semaphore_Release1(p.mFilledSemaphore); } } }
private void MatchFinderMt_Normalize() { CMatchFinder.MatchFinder_Normalize3(mLzPos - mLocalHistorySize - 1, mLocalHash, mLocalFixedHashSize); mLzPos = mLocalHistorySize + 1; }