mirror of
https://github.com/ReneLergner/WPinternals.git
synced 2026-08-10 18:11:14 +10:00
Project Maintenance
This commit is contained in:
@@ -6,30 +6,30 @@ namespace SevenZip.Compression.LZ
|
||||
{
|
||||
public class BinTree : InWindow, IMatchFinder
|
||||
{
|
||||
UInt32 _cyclicBufferPos;
|
||||
UInt32 _cyclicBufferSize = 0;
|
||||
UInt32 _matchMaxLen;
|
||||
private UInt32 _cyclicBufferPos;
|
||||
private UInt32 _cyclicBufferSize = 0;
|
||||
private UInt32 _matchMaxLen;
|
||||
|
||||
UInt32[] _son;
|
||||
UInt32[] _hash;
|
||||
private UInt32[] _son;
|
||||
private UInt32[] _hash;
|
||||
|
||||
UInt32 _cutValue = 0xFF;
|
||||
UInt32 _hashMask;
|
||||
UInt32 _hashSizeSum = 0;
|
||||
private UInt32 _cutValue = 0xFF;
|
||||
private UInt32 _hashMask;
|
||||
private UInt32 _hashSizeSum = 0;
|
||||
|
||||
bool HASH_ARRAY = true;
|
||||
private bool HASH_ARRAY = true;
|
||||
|
||||
const UInt32 kHash2Size = 1 << 10;
|
||||
const UInt32 kHash3Size = 1 << 16;
|
||||
const UInt32 kBT2HashSize = 1 << 16;
|
||||
const UInt32 kStartMaxLen = 1;
|
||||
const UInt32 kHash3Offset = kHash2Size;
|
||||
const UInt32 kEmptyHashValue = 0;
|
||||
const UInt32 kMaxValForNormalize = ((UInt32)1 << 31) - 1;
|
||||
private const UInt32 kHash2Size = 1 << 10;
|
||||
private const UInt32 kHash3Size = 1 << 16;
|
||||
private const UInt32 kBT2HashSize = 1 << 16;
|
||||
private const UInt32 kStartMaxLen = 1;
|
||||
private const UInt32 kHash3Offset = kHash2Size;
|
||||
private const UInt32 kEmptyHashValue = 0;
|
||||
private const UInt32 kMaxValForNormalize = ((UInt32)1 << 31) - 1;
|
||||
|
||||
UInt32 kNumHashDirectBytes = 0;
|
||||
UInt32 kMinMatchCheck = 4;
|
||||
UInt32 kFixHashSize = kHash2Size + kHash3Size;
|
||||
private UInt32 kNumHashDirectBytes = 0;
|
||||
private UInt32 kMinMatchCheck = 4;
|
||||
private UInt32 kFixHashSize = kHash2Size + kHash3Size;
|
||||
|
||||
public void SetType(int numHashBytes)
|
||||
{
|
||||
@@ -55,7 +55,10 @@ namespace SevenZip.Compression.LZ
|
||||
{
|
||||
base.Init();
|
||||
for (UInt32 i = 0; i < _hashSizeSum; i++)
|
||||
{
|
||||
_hash[i] = kEmptyHashValue;
|
||||
}
|
||||
|
||||
_cyclicBufferPos = 0;
|
||||
ReduceOffsets(-1);
|
||||
}
|
||||
@@ -63,10 +66,15 @@ namespace SevenZip.Compression.LZ
|
||||
public new void MovePos()
|
||||
{
|
||||
if (++_cyclicBufferPos >= _cyclicBufferSize)
|
||||
{
|
||||
_cyclicBufferPos = 0;
|
||||
}
|
||||
|
||||
base.MovePos();
|
||||
if (_pos == kMaxValForNormalize)
|
||||
{
|
||||
Normalize();
|
||||
}
|
||||
}
|
||||
|
||||
public new Byte GetIndexByte(Int32 index) { return base.GetIndexByte(index); }
|
||||
@@ -80,11 +88,14 @@ namespace SevenZip.Compression.LZ
|
||||
UInt32 matchMaxLen, UInt32 keepAddBufferAfter)
|
||||
{
|
||||
if (historySize > kMaxValForNormalize - 256)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
_cutValue = 16 + (matchMaxLen >> 1);
|
||||
|
||||
UInt32 windowReservSize = (historySize + keepAddBufferBefore +
|
||||
matchMaxLen + keepAddBufferAfter) / 2 + 256;
|
||||
UInt32 windowReservSize = ((historySize + keepAddBufferBefore +
|
||||
matchMaxLen + keepAddBufferAfter) / 2) + 256;
|
||||
|
||||
base.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);
|
||||
|
||||
@@ -92,7 +103,9 @@ namespace SevenZip.Compression.LZ
|
||||
|
||||
UInt32 cyclicBufferSize = historySize + 1;
|
||||
if (_cyclicBufferSize != cyclicBufferSize)
|
||||
{
|
||||
_son = new UInt32[(_cyclicBufferSize = cyclicBufferSize) * 2];
|
||||
}
|
||||
|
||||
UInt32 hs = kBT2HashSize;
|
||||
|
||||
@@ -106,20 +119,27 @@ namespace SevenZip.Compression.LZ
|
||||
hs >>= 1;
|
||||
hs |= 0xFFFF;
|
||||
if (hs > (1 << 24))
|
||||
{
|
||||
hs >>= 1;
|
||||
}
|
||||
|
||||
_hashMask = hs;
|
||||
hs++;
|
||||
hs += kFixHashSize;
|
||||
}
|
||||
if (hs != _hashSizeSum)
|
||||
{
|
||||
_hash = new UInt32[_hashSizeSum = hs];
|
||||
}
|
||||
}
|
||||
|
||||
public UInt32 GetMatches(UInt32[] distances)
|
||||
{
|
||||
UInt32 lenLimit;
|
||||
if (_pos + _matchMaxLen <= _streamPos)
|
||||
{
|
||||
lenLimit = _matchMaxLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
lenLimit = _streamPos - _pos;
|
||||
@@ -145,7 +165,9 @@ namespace SevenZip.Compression.LZ
|
||||
hashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;
|
||||
}
|
||||
else
|
||||
{
|
||||
hashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);
|
||||
}
|
||||
|
||||
UInt32 curMatch = _hash[kFixHashSize + hashValue];
|
||||
if (HASH_ARRAY)
|
||||
@@ -155,20 +177,29 @@ namespace SevenZip.Compression.LZ
|
||||
_hash[hash2Value] = _pos;
|
||||
_hash[kHash3Offset + hash3Value] = _pos;
|
||||
if (curMatch2 > matchMinPos)
|
||||
{
|
||||
if (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])
|
||||
{
|
||||
distances[offset++] = maxLen = 2;
|
||||
distances[offset++] = _pos - curMatch2 - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (curMatch3 > matchMinPos)
|
||||
{
|
||||
if (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])
|
||||
{
|
||||
if (curMatch3 == curMatch2)
|
||||
{
|
||||
offset -= 2;
|
||||
}
|
||||
|
||||
distances[offset++] = maxLen = 3;
|
||||
distances[offset++] = _pos - curMatch3 - 1;
|
||||
curMatch2 = curMatch3;
|
||||
}
|
||||
}
|
||||
|
||||
if (offset != 0 && curMatch2 == curMatch)
|
||||
{
|
||||
offset -= 2;
|
||||
@@ -216,8 +247,13 @@ namespace SevenZip.Compression.LZ
|
||||
if (_bufferBase[pby1 + len] == _bufferBase[cur + len])
|
||||
{
|
||||
while (++len != lenLimit)
|
||||
{
|
||||
if (_bufferBase[pby1 + len] != _bufferBase[cur + len])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxLen < len)
|
||||
{
|
||||
distances[offset++] = maxLen = len;
|
||||
@@ -255,7 +291,9 @@ namespace SevenZip.Compression.LZ
|
||||
{
|
||||
UInt32 lenLimit;
|
||||
if (_pos + _matchMaxLen <= _streamPos)
|
||||
{
|
||||
lenLimit = _matchMaxLen;
|
||||
}
|
||||
else
|
||||
{
|
||||
lenLimit = _streamPos - _pos;
|
||||
@@ -282,7 +320,9 @@ namespace SevenZip.Compression.LZ
|
||||
hashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;
|
||||
}
|
||||
else
|
||||
{
|
||||
hashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);
|
||||
}
|
||||
|
||||
UInt32 curMatch = _hash[kFixHashSize + hashValue];
|
||||
_hash[kFixHashSize + hashValue] = _pos;
|
||||
@@ -312,8 +352,13 @@ namespace SevenZip.Compression.LZ
|
||||
if (_bufferBase[pby1 + len] == _bufferBase[cur + len])
|
||||
{
|
||||
while (++len != lenLimit)
|
||||
{
|
||||
if (_bufferBase[pby1 + len] != _bufferBase[cur + len])
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (len == lenLimit)
|
||||
{
|
||||
_son[ptr1] = _son[cyclicPos];
|
||||
@@ -341,20 +386,25 @@ namespace SevenZip.Compression.LZ
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
void NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue)
|
||||
private void NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue)
|
||||
{
|
||||
for (UInt32 i = 0; i < numItems; i++)
|
||||
{
|
||||
UInt32 value = items[i];
|
||||
if (value <= subValue)
|
||||
{
|
||||
value = kEmptyHashValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
value -= subValue;
|
||||
}
|
||||
|
||||
items[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
void Normalize()
|
||||
private void Normalize()
|
||||
{
|
||||
UInt32 subValue = _pos - _cyclicBufferSize;
|
||||
NormalizeLinks(_son, _cyclicBufferSize * 2, subValue);
|
||||
|
||||
Reference in New Issue
Block a user