const int kDefaultDictionaryLogSize = 22;
const UInt32 kNumFastBytesDefault = 0x20;
-enum
+enum
{
kBT2,
kBT3,
kHC4
};
-static const wchar_t *kMatchFinderIDs[] =
+static const wchar_t *kMatchFinderIDs[] =
{
L"BT2",
L"BT3",
{
UInt32 context = 1;
int i = 8;
- do
+ do
{
i--;
UInt32 bit = (symbol >> i) & 1;
while(i != 0);
}
-void CLiteralEncoder2::EncodeMatched(NRangeCoder::CEncoder *rangeEncoder,
+void CLiteralEncoder2::EncodeMatched(NRangeCoder::CEncoder *rangeEncoder,
Byte matchByte, Byte symbol)
{
UInt32 context = 1;
int i = 8;
- do
+ do
{
i--;
UInt32 bit = (symbol >> i) & 1;
int i = 8;
if (matchMode)
{
- do
+ do
{
i--;
UInt32 matchBit = (matchByte >> i) & 1;
}
#endif
#endif
-
+
#ifdef COMPRESS_MF_HC
case kHC4:
{
}
#endif
}
-
+
if (!_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits))
return E_OUTOFMEMORY;
return -1;
}
-STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
+STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
const PROPVARIANT *properties, UInt32 numProperties)
{
for (UInt32 i = 0; i < numProperties; i++)
if (prop.vt != VT_UI4)
return E_INVALIDARG;
UInt32 maximize = prop.ulVal;
- _fastMode = (maximize == 0);
+ _fastMode = (maximize == 0);
// _maxMode = (maximize >= 2);
break;
}
}
STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
-{
+{
const UInt32 kPropSize = 5;
Byte properties[kPropSize];
properties[0] = (_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits;
while(cur != 0);
backRes = _optimum[0].BackPrev;
_optimumCurrentIndex = _optimum[0].PosPrev;
- return _optimumCurrentIndex;
+ return _optimumCurrentIndex;
}
/*
return S_OK;
}
_optimumCurrentIndex = _optimumEndIndex = 0;
-
+
UInt32 lenMain, numDistancePairs;
if (!_longestMatchWasFound)
{
continue;
}
UInt32 lenTest;
- for (lenTest = 2; lenTest < numAvailableBytes &&
+ for (lenTest = 2; lenTest < numAvailableBytes &&
data[lenTest] == data[(size_t)lenTest - backOffset]; lenTest++);
repLens[i] = lenTest;
if (lenTest > repLens[repMaxIndex])
UInt32 *matchDistances = _matchDistances + 1;
if(lenMain >= _numFastBytes)
{
- backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances;
+ backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances;
lenRes = lenMain;
return MovePos(lenMain - 1);
}
UInt32 posState = (position & _posStateMask);
- _optimum[1].Price = _isMatch[_state.Index][posState].GetPrice0() +
+ _optimum[1].Price = _isMatch[_state.Index][posState].GetPrice0() +
_literalEncoder.GetSubCoder(position, _previousByte)->GetPrice(!_state.IsCharState(), matchByte, currentByte);
_optimum[1].MakeAsChar();
{
UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState);
COptimal &optimum = _optimum[repLen];
- if (curAndLenPrice < optimum.Price)
+ if (curAndLenPrice < optimum.Price)
{
optimum.Price = curAndLenPrice;
optimum.PosPrev = 0;
UInt32 distance = matchDistances[offs + 1];
UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState);
COptimal &optimum = _optimum[len];
- if (curAndLenPrice < optimum.Price)
+ if (curAndLenPrice < optimum.Price)
{
optimum.Price = curAndLenPrice;
optimum.PosPrev = 0;
curOptimum.State = state;
for(UInt32 i = 0; i < kNumRepDistances; i++)
curOptimum.Backs[i] = reps[i];
- UInt32 curPrice = curOptimum.Price;
+ UInt32 curPrice = curOptimum.Price;
const Byte *data = _matchFinder->GetPointerToCurrentPos() - 1;
const Byte currentByte = *data;
const Byte matchByte = data[(size_t)0 - reps[0] - 1];
COptimal &nextOptimum = _optimum[cur + 1];
bool nextIsChar = false;
- if (curAnd1Price < nextOptimum.Price)
+ if (curAnd1Price < nextOptimum.Price)
{
nextOptimum.Price = curAnd1Price;
nextOptimum.PosPrev = cur;
UInt32 matchPrice = curPrice + _isMatch[state.Index][posState].GetPrice1();
UInt32 repMatchPrice = matchPrice + _isRep[state.Index].GetPrice1();
-
+
if(matchByte == currentByte &&
!(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0))
{
UInt32 backOffset = reps[0] + 1;
UInt32 limit = MyMin(numAvailableBytesFull, _numFastBytes + 1);
UInt32 temp;
- for (temp = 1; temp < limit &&
+ for (temp = 1; temp < limit &&
data[temp] == data[(size_t)temp - backOffset]; temp++);
UInt32 lenTest2 = temp - 1;
if (lenTest2 >= 2)
CState state2 = state;
state2.UpdateChar();
UInt32 posStateNext = (position + 1) & _posStateMask;
- UInt32 nextRepMatchPrice = curAnd1Price +
+ UInt32 nextRepMatchPrice = curAnd1Price +
_isMatch[state2.Index][posStateNext].GetPrice1() +
_isRep[state2.Index].GetPrice1();
// for (; lenTest2 >= 2; lenTest2--)
UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(
0, lenTest2, state2, posStateNext);
COptimal &optimum = _optimum[offset];
- if (curAndLenPrice < optimum.Price)
+ if (curAndLenPrice < optimum.Price)
{
optimum.Price = curAndLenPrice;
optimum.PosPrev = cur + 1;
}
}
}
-
- UInt32 startLen = 2; // speed optimization
+
+ UInt32 startLen = 2; // speed optimization
for(UInt32 repIndex = 0; repIndex < kNumRepDistances; repIndex++)
{
// UInt32 repLen = _matchFinder->GetMatchLen(0 - 1, reps[repIndex], newLen); // test it;
data[1] != data[(size_t)1 - backOffset])
continue;
UInt32 lenTest;
- for (lenTest = 2; lenTest < numAvailableBytes &&
+ for (lenTest = 2; lenTest < numAvailableBytes &&
data[lenTest] == data[(size_t)lenTest - backOffset]; lenTest++);
while(lenEnd < cur + lenTest)
_optimum[++lenEnd].Price = kIfinityPrice;
{
UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState);
COptimal &optimum = _optimum[cur + lenTest];
- if (curAndLenPrice < optimum.Price)
+ if (curAndLenPrice < optimum.Price)
{
optimum.Price = curAndLenPrice;
optimum.PosPrev = cur;
}
while(--lenTest >= 2);
lenTest = lenTestTemp;
-
+
if (repIndex == 0)
startLen = lenTest + 1;
-
+
// if (_maxMode)
{
UInt32 lenTest2 = lenTest + 1;
UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);
- for (; lenTest2 < limit &&
+ for (; lenTest2 < limit &&
data[lenTest2] == data[(size_t)lenTest2 - backOffset]; lenTest2++);
lenTest2 -= lenTest + 1;
if (lenTest2 >= 2)
CState state2 = state;
state2.UpdateRep();
UInt32 posStateNext = (position + lenTest) & _posStateMask;
- UInt32 curAndLenCharPrice =
- price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState) +
+ UInt32 curAndLenCharPrice =
+ price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState) +
_isMatch[state2.Index][posStateNext].GetPrice0() +
_literalEncoder.GetSubCoder(position + lenTest, data[(size_t)lenTest - 1])->GetPrice(
true, data[(size_t)lenTest - backOffset], data[lenTest]);
state2.UpdateChar();
posStateNext = (position + lenTest + 1) & _posStateMask;
- UInt32 nextRepMatchPrice = curAndLenCharPrice +
+ UInt32 nextRepMatchPrice = curAndLenCharPrice +
_isMatch[state2.Index][posStateNext].GetPrice1() +
_isRep[state2.Index].GetPrice1();
-
+
// for(; lenTest2 >= 2; lenTest2--)
{
UInt32 offset = cur + lenTest + 1 + lenTest2;
UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(
0, lenTest2, state2, posStateNext);
COptimal &optimum = _optimum[offset];
- if (curAndLenPrice < optimum.Price)
+ if (curAndLenPrice < optimum.Price)
{
optimum.Price = curAndLenPrice;
optimum.PosPrev = cur + lenTest + 1;
}
}
}
-
+
// for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++)
if (newLen > numAvailableBytes)
{
curAndLenPrice += _distancesPrices[lenToPosState][curBack];
else
curAndLenPrice += _posSlotPrices[lenToPosState][posSlot] + _alignPrices[curBack & kAlignMask];
-
+
curAndLenPrice += _lenEncoder.GetPrice(lenTest - kMatchMinLen, posState);
-
+
COptimal &optimum = _optimum[cur + lenTest];
- if (curAndLenPrice < optimum.Price)
+ if (curAndLenPrice < optimum.Price)
{
optimum.Price = curAndLenPrice;
optimum.PosPrev = cur;
UInt32 backOffset = curBack + 1;
UInt32 lenTest2 = lenTest + 1;
UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes);
- for (; lenTest2 < limit &&
+ for (; lenTest2 < limit &&
data[lenTest2] == data[(size_t)lenTest2 - backOffset]; lenTest2++);
lenTest2 -= lenTest + 1;
if (lenTest2 >= 2)
CState state2 = state;
state2.UpdateMatch();
UInt32 posStateNext = (position + lenTest) & _posStateMask;
- UInt32 curAndLenCharPrice = curAndLenPrice +
+ UInt32 curAndLenCharPrice = curAndLenPrice +
_isMatch[state2.Index][posStateNext].GetPrice0() +
- _literalEncoder.GetSubCoder(position + lenTest, data[(size_t)lenTest - 1])->GetPrice(
+ _literalEncoder.GetSubCoder(position + lenTest, data[(size_t)lenTest - 1])->GetPrice(
true, data[(size_t)lenTest - backOffset], data[lenTest]);
state2.UpdateChar();
posStateNext = (posStateNext + 1) & _posStateMask;
- UInt32 nextRepMatchPrice = curAndLenCharPrice +
+ UInt32 nextRepMatchPrice = curAndLenCharPrice +
_isMatch[state2.Index][posStateNext].GetPrice1() +
_isRep[state2.Index].GetPrice1();
-
+
// for(; lenTest2 >= 2; lenTest2--)
{
UInt32 offset = cur + lenTest + 1 + lenTest2;
_optimum[++lenEnd].Price = kIfinityPrice;
UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext);
COptimal &optimum = _optimum[offset];
- if (curAndLenPrice < optimum.Price)
+ if (curAndLenPrice < optimum.Price)
{
optimum.Price = curAndLenPrice;
optimum.PosPrev = cur + lenTest + 1;
{
lenRes = _matchDistances[1 + numDistancePairs - 2];
if (lenRes == _numFastBytes)
- lenRes += _matchFinder->GetMatchLen(lenRes - 1, _matchDistances[1 + numDistancePairs - 1],
+ lenRes += _matchFinder->GetMatchLen(lenRes - 1, _matchDistances[1 + numDistancePairs - 1],
kMatchMaxLen - lenRes);
}
_additionalOffset++;
UInt32 *matchDistances = _matchDistances + 1;
if(lenMain >= _numFastBytes)
{
- backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances;
+ backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances;
lenRes = lenMain;
return MovePos(lenMain - 1);
}
if (repLens[repMaxIndex] >= 2)
{
- if (repLens[repMaxIndex] + 1 >= lenMain ||
+ if (repLens[repMaxIndex] + 1 >= lenMain ||
repLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 9)) ||
repLens[repMaxIndex] + 3 >= lenMain && (backMain > (1 << 15)))
{
return MovePos(lenRes - 1);
}
}
-
+
if (lenMain >= 2 && numAvailableBytes > 2)
{
RINOK(ReadMatchDistances(_longestMatchLength, _numDistancePairs));
if (_longestMatchLength >= 2)
{
UInt32 newDistance = matchDistances[_numDistancePairs - 1];
- if (_longestMatchLength >= lenMain && newDistance < backMain ||
+ if (_longestMatchLength >= lenMain && newDistance < backMain ||
_longestMatchLength == lenMain + 1 && !ChangePair(backMain, newDistance) ||
_longestMatchLength > lenMain + 1 ||
_longestMatchLength + 1 >= lenMain && lenMain >= 3 && ChangePair(newDistance, backMain))
return S_OK;
}
}
- backRes = backMain + kNumRepDistances;
+ backRes = backMain + kNumRepDistances;
lenRes = lenMain;
return MovePos(lenMain - 2);
}
void CEncoder::WriteEndMarker(UInt32 posState)
{
- // This function for writing End Mark for stream version of LZMA.
+ // This function for writing End Mark for stream version of LZMA.
// In current version this feature is not used.
if (!_writeEndMark)
return;
}
HRESULT CEncoder::CodeReal(ISequentialInStream *inStream,
- ISequentialOutStream *outStream,
+ ISequentialOutStream *outStream,
const UInt64 *inSize, const UInt64 *outSize,
ICompressProgressInfo *progress)
{
}
HRESULT CEncoder::SetStreams(ISequentialInStream *inStream,
- ISequentialOutStream *outStream,
+ ISequentialOutStream *outStream,
const UInt64 *inSize, const UInt64 *outSize)
{
_inStream = inStream;
RINOK(Create());
RINOK(SetOutStream(outStream));
RINOK(Init());
-
+
// CCoderReleaser releaser(this);
/*
pos -= kNumRepDistances;
UInt32 posSlot = GetPosSlot(pos);
_posSlotEncoder[GetLenToPosState(len)].Encode(&_rangeEncoder, posSlot);
-
+
if (posSlot >= kStartPosModelIndex)
{
UInt32 footerBits = ((posSlot >> 1) - 1);
UInt32 posReduced = pos - base;
if (posSlot < kEndPosModelIndex)
- NRangeCoder::ReverseBitTreeEncode(_posEncoders + base - posSlot - 1,
+ NRangeCoder::ReverseBitTreeEncode(_posEncoders + base - posSlot - 1,
&_rangeEncoder, footerBits, posReduced);
else
{
ICompressProgressInfo *progress)
{
#ifndef _NO_EXCEPTIONS
- try
- {
+ try
+ {
#endif
- return CodeReal(inStream, outStream, inSize, outSize, progress);
+ return CodeReal(inStream, outStream, inSize, outSize, progress);
#ifndef _NO_EXCEPTIONS
}
catch(const COutBufferException &e) { return e.ErrorCode; }
catch(...) { return E_FAIL; }
#endif
}
-
+
void CEncoder::FillDistancesPrices()
{
UInt32 tempPrices[kNumFullDistances];
for (UInt32 i = kStartPosModelIndex; i < kNumFullDistances; i++)
- {
+ {
UInt32 posSlot = GetPosSlot(i);
UInt32 footerBits = ((posSlot >> 1) - 1);
UInt32 base = ((2 | (posSlot & 1)) << footerBits);
- tempPrices[i] = NRangeCoder::ReverseBitTreeGetPrice(_posEncoders +
+ tempPrices[i] = NRangeCoder::ReverseBitTreeGetPrice(_posEncoders +
base - posSlot - 1, footerBits, i - base);
}