This commit is contained in:
Igor Pavlov
2005-05-30 00:00:00 +00:00
committed by Kornel Lesiński
parent 8c1b5c7b7e
commit 3c510ba80b
926 changed files with 40559 additions and 23519 deletions

View File

@@ -1,116 +1,55 @@
// BinTree.h
// #pragma once
// #ifndef __BINTREE_H
// #define __BINTREE_H
#include "../LZInWindow.h"
// #include "Common/Types.h"
// #include "Windows/Defs.h"
#include "../IMatchFinder.h"
namespace BT_NAMESPACE {
// #define __USE_3_BYTES
typedef UInt32 CIndex;
const UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;
#ifdef __USE_3_BYTES
#pragma pack(push, PragmaBinTree, 1)
struct CIndex
class CMatchFinderBinTree:
public IMatchFinder,
public IMatchFinderSetCallback,
public CLZInWindow,
public CMyUnknownImp
{
BYTE Data[3];
CIndex(){}
CIndex(UINT32 value)
{
Data[0] = value & 0xFF;
Data[1] = (value >> 8) & 0xFF;
Data[2] = (value >> 16) & 0xFF;
}
operator UINT32() const { return (*((const UINT32 *)Data)) & 0xFFFFFF; }
};
const UINT32 kMaxValForNormalize = CIndex(-1);
#pragma pack(pop, PragmaBinTree)
#else
typedef UINT32 CIndex;
const UINT32 kMaxValForNormalize = (UINT32(1) << 31) - 1;
#endif
// #define HASH_ARRAY_2
// #ifdef HASH_ARRAY_2
// #define HASH_ARRAY_3
// #else
// #define HASH_ZIP
// #endif
#pragma pack(push, PragmaBinTreePair, 1)
// #pragma pack(push, 1)
struct CPair
{
CIndex Left;
CIndex Right;
};
// #pragma pack(pop)
#pragma pack(pop, PragmaBinTreePair)
class CInTree: public CLZInWindow
{
UINT32 _cyclicBufferPos;
UINT32 _cyclicBufferSize;
UINT32 _historySize;
UINT32 _matchMaxLen;
UInt32 _cyclicBufferPos;
UInt32 _cyclicBufferSize; // it must be historySize + 1
UInt32 _matchMaxLen;
CIndex *_hash;
#ifdef HASH_ARRAY_2
CIndex *_hash2;
#ifdef HASH_ARRAY_3
CIndex *_hash3;
#endif
#endif
CPair *_son;
UInt32 _cutValue;
UINT32 _cutValue;
CMyComPtr<IMatchFinderCallback> m_Callback;
void NormalizeLinks(CIndex *array, UINT32 numItems, UINT32 subValue);
void Normalize();
void FreeThisClassMemory();
void FreeMemory();
MY_UNKNOWN_IMP1(IMatchFinderSetCallback)
STDMETHOD(Init)(ISequentialInStream *inStream);
STDMETHOD_(void, ReleaseStream)();
STDMETHOD(MovePos)();
STDMETHOD_(Byte, GetIndexByte)(Int32 index);
STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);
STDMETHOD_(UInt32, GetNumAvailableBytes)();
STDMETHOD_(const Byte *, GetPointerToCurrentPos)();
STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter);
STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);
STDMETHOD_(void, DummyLongestMatch)();
// IMatchFinderSetCallback
STDMETHOD(SetCallback)(IMatchFinderCallback *callback);
virtual void BeforeMoveBlock();
virtual void AfterMoveBlock();
public:
CInTree();
~CInTree();
HRESULT Create(UINT32 sizeHistory, UINT32 keepAddBufferBefore, UINT32 matchMaxLen,
UINT32 keepAddBufferAfter, UINT32 sizeReserv = (1<<17));
HRESULT Init(ISequentialInStream *stream);
void SetCutValue(UINT32 cutValue) { _cutValue = cutValue; }
UINT32 GetLongestMatch(UINT32 *distances);
void DummyLongestMatch();
HRESULT MovePos()
{
_cyclicBufferPos++;
if (_cyclicBufferPos >= _cyclicBufferSize)
_cyclicBufferPos = 0;
RINOK(CLZInWindow::MovePos());
if (_pos == kMaxValForNormalize)
Normalize();
return S_OK;
}
CMatchFinderBinTree();
virtual ~CMatchFinderBinTree();
void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }
};
}
// #endif

View File

@@ -1,18 +1,12 @@
// BinTree2.h
// #pragma once
#ifndef __BINTREE2__H
#define __BINTREE2__H
#undef BT_CLSID
#define BT_CLSID CLSID_CMatchFinderBT2
#ifndef __BINTREE2_H
#define __BINTREE2_H
#undef BT_NAMESPACE
#define BT_NAMESPACE NBT2
#include "BinTreeMF.h"
#include "BinTreeMFMain.h"
#include "BinTree.h"
#include "BinTreeMain.h"
#endif

View File

@@ -1,22 +1,16 @@
// BinTree3.h
// #pragma once
#ifndef __BINTREE3__H
#define __BINTREE3__H
#undef BT_CLSID
#define BT_CLSID CLSID_CMatchFinderBT3
#ifndef __BINTREE3_H
#define __BINTREE3_H
#undef BT_NAMESPACE
#define BT_NAMESPACE NBT3
#define HASH_ARRAY_2
#include "BinTreeMF.h"
#include "BinTreeMFMain.h"
#include "BinTree.h"
#include "BinTreeMain.h"
#undef HASH_ARRAY_2
#endif

View File

@@ -1,9 +1,7 @@
// BinTree3Z.h
// #pragma once
#ifndef __BINTREE3Z__H
#define __BINTREE3Z__H
#ifndef __BINTREE3Z_H
#define __BINTREE3Z_H
#undef BT_NAMESPACE
#define BT_NAMESPACE NBT3Z
@@ -11,9 +9,8 @@
#define HASH_ZIP
#include "BinTree.h"
// #include "BinTreeMain.h"
#include "BinTreeMain.h"
#undef HASH_ZIP
#endif

View File

@@ -1,18 +0,0 @@
// BinTree3ZMain.h
// #pragma once
#ifndef __BINTREE3ZMAIN__H
#define __BINTREE3ZMAIN__H
#undef BT_NAMESPACE
#define BT_NAMESPACE NBT3Z
#define HASH_ZIP
#include "BinTreeMain.h"
#undef HASH_ZIP
#endif

View File

@@ -1,12 +1,7 @@
// BinTree4.h
// #pragma once
#ifndef __BINTREE4__H
#define __BINTREE4__H
#undef BT_CLSID
#define BT_CLSID CLSID_CMatchFinderBT4
#ifndef __BINTREE4_H
#define __BINTREE4_H
#undef BT_NAMESPACE
#define BT_NAMESPACE NBT4
@@ -14,11 +9,10 @@
#define HASH_ARRAY_2
#define HASH_ARRAY_3
#include "BinTreeMF.h"
#include "BinTreeMFMain.h"
#include "BinTree.h"
#include "BinTreeMain.h"
#undef HASH_ARRAY_2
#undef HASH_ARRAY_3
#endif

View File

@@ -1,12 +1,7 @@
// BinTree4b.h
// #pragma once
#ifndef __BINTREE4B__H
#define __BINTREE4B__H
#undef BT_CLSID
#define BT_CLSID CLSID_CMatchFinderBT4b
#ifndef __BINTREE4B_H
#define __BINTREE4B_H
#undef BT_NAMESPACE
#define BT_NAMESPACE NBT4B
@@ -15,12 +10,11 @@
#define HASH_ARRAY_3
#define HASH_BIG
#include "BinTreeMF.h"
#include "BinTreeMFMain.h"
#include "BinTree.h"
#include "BinTreeMain.h"
#undef HASH_ARRAY_2
#undef HASH_ARRAY_3
#undef HASH_BIG
#endif

View File

@@ -1,110 +0,0 @@
// BinTreeMF.h
// #pragma once
// #ifndef __BINTREEMF_H
// #define __BINTREEMF_H
#include "../../../ICoder.h"
#include "BinTree.h"
namespace BT_NAMESPACE {
#undef kIDByte
#undef kIDString
#ifdef HASH_ARRAY_2
#ifdef HASH_ARRAY_3
#ifdef HASH_BIG
#define kIDByte 0x4
#define kIDString TEXT("4b")
#else
#define kIDByte 0x3
#define kIDString TEXT("4")
#endif
#else
#define kIDByte 0x2
#define kIDString TEXT("3")
#endif
#else
#ifdef HASH_ZIP
#define kIDByte 0x0
#define kIDString TEXT("3Z")
#else
#define kIDByte 0x1
#define kIDString TEXT("2")
#endif
#endif
#undef kIDUse3BytesByte
#undef kIDUse3BytesString
#ifdef __USE_3_BYTES
#define kIDUse3BytesByte 0x80
#define kIDUse3BytesString TEXT("T")
#else
#define kIDUse3BytesByte 0x00
#define kIDUse3BytesString TEXT("")
#endif
// #undef kIDStringFull
// #define kIDStringFull TEXT("Compress.MatchFinderBT") kIDString kIDUse3BytesString
// {23170F69-40C1-278C-02XX-0000000000}
DEFINE_GUID(BT_CLSID,
0x23170F69, 0x40C1, 0x278C, 0x02, kIDByte | kIDUse3BytesByte,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
class CInTree2: public CInTree
{
CMyComPtr<IMatchFinderCallback> _callback;
virtual void BeforeMoveBlock();
virtual void AfterMoveBlock();
public:
void SetCallback(IMatchFinderCallback *callback)
{
_callback = callback;
}
};
class CMatchFinderBinTree:
public IMatchFinder,
public IMatchFinderSetCallback,
public CMyUnknownImp
{
MY_UNKNOWN_IMP1(IMatchFinderSetCallback)
STDMETHOD(Init)(ISequentialInStream *stream);
STDMETHOD_(void, ReleaseStream)();
STDMETHOD(MovePos)();
STDMETHOD_(BYTE, GetIndexByte)(UINT32 index);
STDMETHOD_(UINT32, GetMatchLen)(UINT32 index, UINT32 back, UINT32 limit);
STDMETHOD_(UINT32, GetNumAvailableBytes)();
STDMETHOD_(const BYTE *, GetPointerToCurrentPos)();
STDMETHOD(Create)(UINT32 sizeHistory,
UINT32 keepAddBufferBefore, UINT32 matchMaxLen,
UINT32 keepAddBufferAfter);
STDMETHOD_(UINT32, GetLongestMatch)(UINT32 *distances);
STDMETHOD_(void, DummyLongestMatch)();
// IMatchFinderSetCallback
STDMETHOD(SetCallback)(IMatchFinderCallback *callback);
private:
// UINT32 m_WindowReservSize;
CInTree2 _matchFinder;
public:
// CMatchFinderBinTree(): m_WindowReservSize((1 << 19) + 256) {};
void SetCutValue(UINT32 cutValue)
{ _matchFinder.SetCutValue(cutValue); }
/*
void SetWindowReservSize(UINT32 reservWindowSize)
{ m_WindowReservSize = reservWindowSize; }
*/
};
}
// #endif

View File

@@ -1,81 +0,0 @@
// BinTreeMFMain.h
// #include "StdAfx.h"
// #include "BinTreeMF.h"
#include "BinTreeMain.h"
namespace BT_NAMESPACE {
void CInTree2::BeforeMoveBlock()
{
if (_callback)
_callback->BeforeChangingBufferPos();
CInTree::BeforeMoveBlock();
}
void CInTree2::AfterMoveBlock()
{
CInTree::AfterMoveBlock();
if (_callback)
_callback->AfterChangingBufferPos();
}
STDMETHODIMP CMatchFinderBinTree::Init(ISequentialInStream *stream)
{ return _matchFinder.Init(stream); }
STDMETHODIMP_(void) CMatchFinderBinTree::ReleaseStream()
{
// _matchFinder.ReleaseStream();
}
STDMETHODIMP CMatchFinderBinTree::MovePos()
{ return _matchFinder.MovePos(); }
STDMETHODIMP_(BYTE) CMatchFinderBinTree::GetIndexByte(UINT32 index)
{ return _matchFinder.GetIndexByte(index); }
STDMETHODIMP_(UINT32) CMatchFinderBinTree::GetMatchLen(UINT32 index,
UINT32 back, UINT32 limit)
{ return _matchFinder.GetMatchLen(index, back, limit); }
STDMETHODIMP_(UINT32) CMatchFinderBinTree::GetNumAvailableBytes()
{ return _matchFinder.GetNumAvailableBytes(); }
STDMETHODIMP CMatchFinderBinTree::Create(UINT32 sizeHistory,
UINT32 keepAddBufferBefore, UINT32 matchMaxLen,
UINT32 keepAddBufferAfter)
{
UINT32 windowReservSize = (sizeHistory + keepAddBufferBefore +
matchMaxLen + keepAddBufferAfter) / 2 + 256;
try
{
return _matchFinder.Create(sizeHistory, keepAddBufferBefore,
matchMaxLen, keepAddBufferAfter, windowReservSize);
}
catch(...)
{
return E_OUTOFMEMORY;
}
}
STDMETHODIMP_(UINT32) CMatchFinderBinTree::GetLongestMatch(UINT32 *distances)
{ return _matchFinder.GetLongestMatch(distances); }
STDMETHODIMP_(void) CMatchFinderBinTree::DummyLongestMatch()
{ _matchFinder.DummyLongestMatch(); }
STDMETHODIMP_(const BYTE *) CMatchFinderBinTree::GetPointerToCurrentPos()
{
return _matchFinder.GetPointerToCurrentPos();
}
// IMatchFinderSetCallback
STDMETHODIMP CMatchFinderBinTree::SetCallback(IMatchFinderCallback *callback)
{
_matchFinder.SetCallback(callback);
return S_OK;
}
}

View File

@@ -1,542 +1,444 @@
// BinTreemain.h
// #include "StdAfx.h"
// #include "BinTree.h"
// #include "Common/NewHandler.h"
// BinTreeMain.h
#include "../../../../Common/Defs.h"
#include "../../../../Common/CRC.h"
#include "../../../../Common/Alloc.h"
namespace BT_NAMESPACE {
#ifdef HASH_ARRAY_2
static const UINT32 kHash2Size = 1 << 10;
static const UInt32 kHash2Size = 1 << 10;
#ifdef HASH_ARRAY_3
static const UINT32 kNumHashDirectBytes = 0;
static const UINT32 kNumHashBytes = 4;
static const UINT32 kHash3Size = 1 << 18;
static const UInt32 kNumHashDirectBytes = 0;
static const UInt32 kNumHashBytes = 4;
static const UInt32 kHash3Size = 1 << 18;
#ifdef HASH_BIG
static const UINT32 kHashSize = 1 << 23;
static const UInt32 kHashSize = 1 << 23;
#else
static const UINT32 kHashSize = 1 << 20;
static const UInt32 kHashSize = 1 << 20;
#endif
#else
static const UINT32 kNumHashDirectBytes = 3;
static const UINT32 kNumHashBytes = 3;
static const UINT32 kHashSize = 1 << (8 * kNumHashBytes);
static const UInt32 kNumHashDirectBytes = 3;
static const UInt32 kNumHashBytes = 3;
static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);
#endif
#else
#ifdef HASH_ZIP
static const UINT32 kNumHashDirectBytes = 0;
static const UINT32 kNumHashBytes = 3;
static const UINT32 kHashSize = 1 << 16;
static const UInt32 kNumHashDirectBytes = 0;
static const UInt32 kNumHashBytes = 3;
static const UInt32 kHashSize = 1 << 16;
#else
static const UINT32 kNumHashDirectBytes = 2;
static const UINT32 kNumHashBytes = 2;
static const UINT32 kHashSize = 1 << (8 * kNumHashBytes);
#define THERE_ARE_DIRECT_HASH_BYTES
static const UInt32 kNumHashDirectBytes = 2;
static const UInt32 kNumHashBytes = 2;
static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);
#endif
#endif
static const UInt32 kHashSizeSum = kHashSize
#ifdef HASH_ARRAY_2
+ kHash2Size
#ifdef HASH_ARRAY_3
+ kHash3Size
#endif
#endif
;
CInTree::CInTree():
#ifdef HASH_ARRAY_2
_hash2(0),
#ifdef HASH_ARRAY_3
_hash3(0),
#endif
#endif
#ifdef HASH_ARRAY_2
static const UInt32 kHash2Offset = kHashSize;
#ifdef HASH_ARRAY_3
static const UInt32 kHash3Offset = kHashSize + kHash2Size;
#endif
#endif
CMatchFinderBinTree::CMatchFinderBinTree():
_hash(0),
_son(0),
_cutValue(0xFF)
{
}
void CInTree::FreeMemory()
void CMatchFinderBinTree::FreeThisClassMemory()
{
#ifdef WIN32
if (_son != 0)
VirtualFree(_son, 0, MEM_RELEASE);
if (_hash != 0)
VirtualFree(_hash, 0, MEM_RELEASE);
#else
delete []_son;
delete []_hash;
#endif
_son = 0;
BigFree(_hash);
_hash = 0;
}
void CMatchFinderBinTree::FreeMemory()
{
FreeThisClassMemory();
CLZInWindow::Free();
}
CInTree::~CInTree()
CMatchFinderBinTree::~CMatchFinderBinTree()
{
FreeMemory();
}
HRESULT CInTree::Create(UINT32 sizeHistory, UINT32 keepAddBufferBefore,
UINT32 matchMaxLen, UINT32 keepAddBufferAfter, UINT32 sizeReserv)
STDMETHODIMP CMatchFinderBinTree::Create(UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter)
{
FreeMemory();
try
UInt32 sizeReserv = (historySize + keepAddBufferBefore +
matchMaxLen + keepAddBufferAfter) / 2 + 256;
if (CLZInWindow::Create(historySize + keepAddBufferBefore,
matchMaxLen + keepAddBufferAfter, sizeReserv))
{
CLZInWindow::Create(sizeHistory + keepAddBufferBefore,
matchMaxLen + keepAddBufferAfter, sizeReserv);
if (_blockSize + 256 > kMaxValForNormalize)
if (historySize + 256 > kMaxValForNormalize)
{
FreeMemory();
return E_INVALIDARG;
_historySize = sizeHistory;
}
_matchMaxLen = matchMaxLen;
_cyclicBufferSize = sizeHistory + 1;
UINT32 size = kHashSize;
#ifdef HASH_ARRAY_2
size += kHash2Size;
#ifdef HASH_ARRAY_3
size += kHash3Size;
#endif
#endif
#ifdef WIN32
_son = (CPair *)::VirtualAlloc(0, (_cyclicBufferSize + 1) * sizeof(CPair), MEM_COMMIT, PAGE_READWRITE);
if (_son == 0)
throw 1; // CNewException();
_hash = (CIndex *)::VirtualAlloc(0, (size + 1) * sizeof(CIndex), MEM_COMMIT, PAGE_READWRITE);
if (_hash == 0)
throw 1; // CNewException();
#else
_son = new CPair[_cyclicBufferSize + 1];
_hash = new CIndex[size + 1];
#endif
// m_RightBase = &m_LeftBase[_blockSize];
// _hash = &m_RightBase[_blockSize];
#ifdef HASH_ARRAY_2
_hash2 = &_hash[kHashSize];
#ifdef HASH_ARRAY_3
_hash3 = &_hash2[kHash2Size];
#endif
#endif
return S_OK;
}
catch(...)
{
FreeMemory();
return E_OUTOFMEMORY;
UInt32 newCyclicBufferSize = historySize + 1;
if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize)
return S_OK;
FreeThisClassMemory();
_cyclicBufferSize = newCyclicBufferSize; // don't change it
_hash = (CIndex *)BigAlloc((kHashSizeSum + _cyclicBufferSize * 2) * sizeof(CIndex));
if (_hash != 0)
return S_OK;
}
FreeMemory();
return E_OUTOFMEMORY;
}
static const UINT32 kEmptyHashValue = 0;
static const UInt32 kEmptyHashValue = 0;
HRESULT CInTree::Init(ISequentialInStream *stream)
STDMETHODIMP CMatchFinderBinTree::Init(ISequentialInStream *stream)
{
RINOK(CLZInWindow::Init(stream));
int i;
for(i = 0; i < kHashSize; i++)
for(UInt32 i = 0; i < kHashSizeSum; i++)
_hash[i] = kEmptyHashValue;
#ifdef HASH_ARRAY_2
for(i = 0; i < kHash2Size; i++)
_hash2[i] = kEmptyHashValue;
#ifdef HASH_ARRAY_3
for(i = 0; i < kHash3Size; i++)
_hash3[i] = kEmptyHashValue;
#endif
#endif
_cyclicBufferPos = 0;
ReduceOffsets(0 - 1);
ReduceOffsets(-1);
return S_OK;
}
STDMETHODIMP_(void) CMatchFinderBinTree::ReleaseStream()
{
// ReleaseStream();
}
#ifdef HASH_ARRAY_2
#ifdef HASH_ARRAY_3
inline UINT32 Hash(const BYTE *pointer, UINT32 &hash2Value, UINT32 &hash3Value)
inline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value, UInt32 &hash3Value)
{
UINT32 temp = CCRC::Table[pointer[0]] ^ pointer[1];
UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];
hash2Value = temp & (kHash2Size - 1);
hash3Value = (temp ^ (UINT32(pointer[2]) << 8)) & (kHash3Size - 1);
return (temp ^ (UINT32(pointer[2]) << 8) ^ (CCRC::Table[pointer[3]] << 5)) &
hash3Value = (temp ^ (UInt32(pointer[2]) << 8)) & (kHash3Size - 1);
return (temp ^ (UInt32(pointer[2]) << 8) ^ (CCRC::Table[pointer[3]] << 5)) &
(kHashSize - 1);
}
#else // no HASH_ARRAY_3
inline UINT32 Hash(const BYTE *pointer, UINT32 &hash2Value)
inline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value)
{
hash2Value = (CCRC::Table[pointer[0]] ^ pointer[1]) & (kHash2Size - 1);
return (*((const UINT32 *)pointer)) & 0xFFFFFF;
return ((UInt32(pointer[0]) << 16)) | ((UInt32(pointer[1]) << 8)) | pointer[2];
}
#endif // HASH_ARRAY_3
#else // no HASH_ARRAY_2
#ifdef HASH_ZIP
inline UINT32 Hash(const BYTE *pointer)
inline UInt32 Hash(const Byte *pointer)
{
return ((UINT32(pointer[0]) << 8) ^
return ((UInt32(pointer[0]) << 8) ^
CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);
}
#else // no HASH_ZIP
inline UINT32 Hash(const BYTE *pointer)
inline UInt32 Hash(const Byte *pointer)
{
return pointer[0] ^ (UINT32(pointer[1]) << 8);
return pointer[0] ^ (UInt32(pointer[1]) << 8);
}
#endif // HASH_ZIP
#endif // HASH_ARRAY_2
UINT32 CInTree::GetLongestMatch(UINT32 *distances)
STDMETHODIMP_(UInt32) CMatchFinderBinTree::GetLongestMatch(UInt32 *distances)
{
UINT32 currentLimit;
UInt32 lenLimit;
if (_pos + _matchMaxLen <= _streamPos)
currentLimit = _matchMaxLen;
lenLimit = _matchMaxLen;
else
{
currentLimit = _streamPos - _pos;
if(currentLimit < kNumHashBytes)
lenLimit = _streamPos - _pos;
if(lenLimit < kNumHashBytes)
return 0;
}
UINT32 matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;
BYTE *cur = _buffer + _pos;
UINT32 matchHashLenMax = 0;
UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
Byte *cur = _buffer + _pos;
UInt32 maxLen = 0;
#ifdef HASH_ARRAY_2
UINT32 hash2Value;
UInt32 hash2Value;
#ifdef HASH_ARRAY_3
UINT32 hash3Value;
UINT32 hashValue = Hash(cur, hash2Value, hash3Value);
UInt32 hash3Value;
UInt32 hashValue = Hash(cur, hash2Value, hash3Value);
#else
UINT32 hashValue = Hash(cur, hash2Value);
UInt32 hashValue = Hash(cur, hash2Value);
#endif
#else
UINT32 hashValue = Hash(cur);
UInt32 hashValue = Hash(cur);
#endif
UINT32 curMatch = _hash[hashValue];
UInt32 curMatch = _hash[hashValue];
#ifdef HASH_ARRAY_2
UINT32 curMatch2 = _hash2[hash2Value];
UInt32 curMatch2 = _hash[kHash2Offset + hash2Value];
#ifdef HASH_ARRAY_3
UINT32 curMatch3 = _hash3[hash3Value];
UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];
#endif
_hash2[hash2Value] = _pos;
bool matchLen2Exist = false;
UINT32 len2Distance = 0;
if(curMatch2 >= matchMinPos)
{
_hash[kHash2Offset + hash2Value] = _pos;
distances[2] = 0xFFFFFFFF;
if(curMatch2 > matchMinPos)
if (_buffer[curMatch2] == cur[0])
{
len2Distance = _pos - curMatch2 - 1;
matchHashLenMax = 2;
matchLen2Exist = true;
distances[2] = _pos - curMatch2 - 1;
maxLen = 2;
}
}
#ifdef HASH_ARRAY_3
_hash3[hash3Value] = _pos;
UINT32 matchLen3Exist = false;
UINT32 len3Distance = 0;
if(curMatch3 >= matchMinPos)
{
_hash[kHash3Offset + hash3Value] = _pos;
distances[3] = 0xFFFFFFFF;
if(curMatch3 > matchMinPos)
if (_buffer[curMatch3] == cur[0])
{
len3Distance = _pos - curMatch3 - 1;
matchHashLenMax = 3;
matchLen3Exist = true;
if (matchLen2Exist)
{
if (len3Distance < len2Distance)
len2Distance = len3Distance;
}
else
{
len2Distance = len3Distance;
matchLen2Exist = true;
}
distances[3] = _pos - curMatch3 - 1;
maxLen = 3;
}
}
#endif
#endif
_hash[hashValue] = _pos;
if(curMatch < matchMinPos)
CIndex *son = _hash + kHashSizeSum;
CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;
CIndex *ptr1 = son + (_cyclicBufferPos << 1);
distances[kNumHashBytes] = 0xFFFFFFFF;
#ifdef THERE_ARE_DIRECT_HASH_BYTES
if (lenLimit == kNumHashDirectBytes)
{
_son[_cyclicBufferPos].Left = kEmptyHashValue;
_son[_cyclicBufferPos].Right = kEmptyHashValue;
#ifdef HASH_ARRAY_2
distances[2] = len2Distance;
#ifdef HASH_ARRAY_3
distances[3] = len3Distance;
#endif
#endif
return matchHashLenMax;
if(curMatch > matchMinPos)
while (maxLen < kNumHashDirectBytes)
distances[++maxLen] = _pos - curMatch - 1;
// We don't need tree in this case
}
CIndex *ptrLeft = &_son[_cyclicBufferPos].Right;
CIndex *ptrRight = &_son[_cyclicBufferPos].Left;
UINT32 maxLen, minSameLeft, minSameRight, minSame;
maxLen = minSameLeft = minSameRight = minSame = kNumHashDirectBytes;
#ifdef HASH_ARRAY_2
#ifndef HASH_ARRAY_3
if (matchLen2Exist)
distances[2] = len2Distance;
else
if (kNumHashDirectBytes >= 2)
distances[2] = _pos - curMatch - 1;
else
#endif
#endif
distances[maxLen] = _pos - curMatch - 1;
for(UINT32 count = _cutValue; count > 0; count--)
{
BYTE *pby1 = _buffer + curMatch;
// CIndex left = _son[curMatch].Left; // it's prefetch
UINT32 currentLen;
for(currentLen = minSame; currentLen < currentLimit; currentLen++/*, dwComps++*/)
if (pby1[currentLen] != cur[currentLen])
UInt32 len0, len1;
len0 = len1 = kNumHashDirectBytes;
UInt32 count = _cutValue;
while(true)
{
if(curMatch <= matchMinPos || count-- == 0)
{
*ptr0 = kEmptyHashValue;
*ptr1 = kEmptyHashValue;
break;
while (currentLen > maxLen)
distances[++maxLen] = _pos - curMatch - 1;
UINT32 delta = _pos - curMatch;
UINT32 cyclicPos = (delta <= _cyclicBufferPos) ?
(_cyclicBufferPos - delta):
(_cyclicBufferPos - delta + _cyclicBufferSize);
if (currentLen != currentLimit)
{
if (pby1[currentLen] < cur[currentLen])
}
Byte *pb = _buffer + curMatch;
UInt32 len = MyMin(len0, len1);
do
{
*ptrRight = curMatch;
ptrRight = &_son[cyclicPos].Right;
curMatch = _son[cyclicPos].Right;
if(currentLen > minSameLeft)
if (pb[len] != cur[len])
break;
}
while(++len != lenLimit);
UInt32 delta = _pos - curMatch;
while (maxLen < len)
distances[++maxLen] = delta - 1;
UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?
(_cyclicBufferPos - delta):
(_cyclicBufferPos - delta + _cyclicBufferSize);
CIndex *pair = son + (cyclicPos << 1);
if (len != lenLimit)
{
if (pb[len] < cur[len])
{
minSameLeft = currentLen;
minSame = MyMin(minSameLeft, minSameRight);
*ptr1 = curMatch;
ptr1 = pair + 1;
curMatch = *ptr1;
len1 = len;
}
else
{
*ptr0 = curMatch;
ptr0 = pair;
curMatch = *ptr0;
len0 = len;
}
}
else
{
*ptrLeft = curMatch;
ptrLeft = &_son[cyclicPos].Left;
// curMatch = left;
curMatch = _son[cyclicPos].Left;
if(currentLen > minSameRight)
{
minSameRight = currentLen;
minSame = MyMin(minSameLeft, minSameRight);
}
*ptr1 = pair[0];
*ptr0 = pair[1];
break;
}
}
else
{
if(currentLen < _matchMaxLen)
{
*ptrLeft = curMatch;
ptrLeft = &_son[cyclicPos].Left;
curMatch = _son[cyclicPos].Left;
if(currentLen > minSameRight)
{
minSameRight = currentLen;
minSame = MyMin(minSameLeft, minSameRight);
}
}
else
{
*ptrLeft = _son[cyclicPos].Right;
*ptrRight = _son[cyclicPos].Left;
#ifdef HASH_ARRAY_2
if (matchLen2Exist && len2Distance < distances[2])
distances[2] = len2Distance;
#ifdef HASH_ARRAY_3
if (matchLen3Exist && len3Distance < distances[3])
distances[3] = len3Distance;
#endif
#endif
return maxLen;
}
}
if(curMatch < matchMinPos)
break;
}
*ptrLeft = kEmptyHashValue;
*ptrRight = kEmptyHashValue;
#ifdef HASH_ARRAY_2
if (matchLen2Exist)
{
if (maxLen < 2)
{
distances[2] = len2Distance;
maxLen = 2;
}
else if (len2Distance < distances[2])
distances[2] = len2Distance;
}
#ifdef HASH_ARRAY_3
if (matchLen3Exist)
{
if (maxLen < 3)
{
distances[3] = len3Distance;
maxLen = 3;
}
else if (len3Distance < distances[3])
distances[3] = len3Distance;
}
if (distances[4] < distances[3])
distances[3] = distances[4];
#endif
if (distances[3] < distances[2])
distances[2] = distances[3];
#endif
return maxLen;
}
void CInTree::DummyLongestMatch()
STDMETHODIMP_(void) CMatchFinderBinTree::DummyLongestMatch()
{
UINT32 currentLimit;
UInt32 lenLimit;
if (_pos + _matchMaxLen <= _streamPos)
currentLimit = _matchMaxLen;
lenLimit = _matchMaxLen;
else
{
currentLimit = _streamPos - _pos;
if(currentLimit < kNumHashBytes)
lenLimit = _streamPos - _pos;
if(lenLimit < kNumHashBytes)
return;
}
UINT32 matchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;
BYTE *cur = _buffer + _pos;
UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
Byte *cur = _buffer + _pos;
#ifdef HASH_ARRAY_2
UINT32 hash2Value;
UInt32 hash2Value;
#ifdef HASH_ARRAY_3
UINT32 hash3Value;
UINT32 hashValue = Hash(cur, hash2Value, hash3Value);
_hash3[hash3Value] = _pos;
UInt32 hash3Value;
UInt32 hashValue = Hash(cur, hash2Value, hash3Value);
_hash[kHash3Offset + hash3Value] = _pos;
#else
UINT32 hashValue = Hash(cur, hash2Value);
UInt32 hashValue = Hash(cur, hash2Value);
#endif
_hash2[hash2Value] = _pos;
_hash[kHash2Offset + hash2Value] = _pos;
#else
UINT32 hashValue = Hash(cur);
UInt32 hashValue = Hash(cur);
#endif
UINT32 curMatch = _hash[hashValue];
UInt32 curMatch = _hash[hashValue];
_hash[hashValue] = _pos;
if(curMatch < matchMinPos)
{
_son[_cyclicBufferPos].Left = kEmptyHashValue;
_son[_cyclicBufferPos].Right = kEmptyHashValue;
return;
}
CIndex *ptrLeft = &_son[_cyclicBufferPos].Right;
CIndex *ptrRight = &_son[_cyclicBufferPos].Left;
CIndex *son = _hash + kHashSizeSum;
CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;
CIndex *ptr1 = son + (_cyclicBufferPos << 1);
UINT32 maxLen, minSameLeft, minSameRight, minSame;
maxLen = minSameLeft = minSameRight = minSame = kNumHashDirectBytes;
for(UINT32 count = _cutValue; count > 0; count--)
#ifdef THERE_ARE_DIRECT_HASH_BYTES
if (lenLimit != kNumHashDirectBytes)
#endif
{
BYTE *pby1 = _buffer + curMatch;
// CIndex left = _son[curMatch].Left; // it's prefetch
UINT32 currentLen;
for(currentLen = minSame; currentLen < currentLimit; currentLen++/*, dwComps++*/)
if (pby1[currentLen] != cur[currentLen])
UInt32 len0, len1;
len0 = len1 = kNumHashDirectBytes;
UInt32 count = _cutValue;
while(true)
{
if(curMatch <= matchMinPos || count-- == 0)
break;
UINT32 delta = _pos - curMatch;
UINT32 cyclicPos = (delta <= _cyclicBufferPos) ?
Byte *pb = _buffer + curMatch;
UInt32 len = MyMin(len0, len1);
do
{
if (pb[len] != cur[len])
break;
}
while(++len != lenLimit);
UInt32 delta = _pos - curMatch;
UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?
(_cyclicBufferPos - delta):
(_cyclicBufferPos - delta + _cyclicBufferSize);
if (currentLen != currentLimit)
{
if (pby1[currentLen] < cur[currentLen])
(_cyclicBufferPos - delta + _cyclicBufferSize);
CIndex *pair = son + (cyclicPos << 1);
if (len != lenLimit)
{
*ptrRight = curMatch;
ptrRight = &_son[cyclicPos].Right;
curMatch = _son[cyclicPos].Right;
if(currentLen > minSameLeft)
if (pb[len] < cur[len])
{
minSameLeft = currentLen;
minSame = MyMin(minSameLeft, minSameRight);
*ptr1 = curMatch;
ptr1 = pair + 1;
curMatch = *ptr1;
len1 = len;
}
}
else
{
*ptrLeft = curMatch;
ptrLeft = &_son[cyclicPos].Left;
curMatch = _son[cyclicPos].Left;
// curMatch = left;
if(currentLen > minSameRight)
else
{
minSameRight = currentLen;
minSame = MyMin(minSameLeft, minSameRight);
}
}
}
else
{
if(currentLen < _matchMaxLen)
{
*ptrLeft = curMatch;
ptrLeft = &_son[cyclicPos].Left;
curMatch = _son[cyclicPos].Left;
if(currentLen > minSameRight)
{
minSameRight = currentLen;
minSame = MyMin(minSameLeft, minSameRight);
*ptr0 = curMatch;
ptr0 = pair;
curMatch = *ptr0;
len0 = len;
}
}
else
{
*ptrLeft = _son[cyclicPos].Right;
*ptrRight = _son[cyclicPos].Left;
*ptr1 = pair[0];
*ptr0 = pair[1];
return;
}
}
if(curMatch < matchMinPos)
break;
}
*ptrLeft = kEmptyHashValue;
*ptrRight = kEmptyHashValue;
*ptr0 = kEmptyHashValue;
*ptr1 = kEmptyHashValue;
}
void CInTree::NormalizeLinks(CIndex *array, UINT32 numItems, UINT32 subValue)
void CMatchFinderBinTree::Normalize()
{
for (UINT32 i = 0; i < numItems; i++)
UInt32 subValue = _pos - _cyclicBufferSize;
CIndex *items = _hash;
UInt32 numItems = (kHashSizeSum + _cyclicBufferSize * 2);
for (UInt32 i = 0; i < numItems; i++)
{
UINT32 value = array[i];
UInt32 value = items[i];
if (value <= subValue)
value = kEmptyHashValue;
else
value -= subValue;
array[i] = value;
items[i] = value;
}
ReduceOffsets(subValue);
}
void CInTree::Normalize()
STDMETHODIMP CMatchFinderBinTree::MovePos()
{
UINT32 startItem = _pos - _historySize;
UINT32 subValue = startItem - 1;
// NormalizeLinks((CIndex *)(_son + startItem), _historySize * 2, subValue);
NormalizeLinks((CIndex *)_son, _cyclicBufferSize * 2, subValue);
NormalizeLinks(_hash, kHashSize, subValue);
if (++_cyclicBufferPos == _cyclicBufferSize)
_cyclicBufferPos = 0;
RINOK(CLZInWindow::MovePos());
if (_pos == kMaxValForNormalize)
Normalize();
return S_OK;
}
#ifdef HASH_ARRAY_2
NormalizeLinks(_hash2, kHash2Size, subValue);
#ifdef HASH_ARRAY_3
NormalizeLinks(_hash3, kHash3Size, subValue);
#endif
#endif
STDMETHODIMP_(Byte) CMatchFinderBinTree::GetIndexByte(Int32 index)
{ return CLZInWindow::GetIndexByte(index); }
ReduceOffsets(subValue);
STDMETHODIMP_(UInt32) CMatchFinderBinTree::GetMatchLen(Int32 index,
UInt32 back, UInt32 limit)
{ return CLZInWindow::GetMatchLen(index, back, limit); }
STDMETHODIMP_(UInt32) CMatchFinderBinTree::GetNumAvailableBytes()
{ return CLZInWindow::GetNumAvailableBytes(); }
STDMETHODIMP_(const Byte *) CMatchFinderBinTree::GetPointerToCurrentPos()
{ return CLZInWindow::GetPointerToCurrentPos(); }
// IMatchFinderSetCallback
STDMETHODIMP CMatchFinderBinTree::SetCallback(IMatchFinderCallback *callback)
{
m_Callback = callback;
return S_OK;
}
void CMatchFinderBinTree::BeforeMoveBlock()
{
if (m_Callback)
m_Callback->BeforeChangingBufferPos();
CLZInWindow::BeforeMoveBlock();
}
void CMatchFinderBinTree::AfterMoveBlock()
{
if (m_Callback)
m_Callback->AfterChangingBufferPos();
CLZInWindow::AfterMoveBlock();
}
}

View File

@@ -1,108 +1,55 @@
// HC.h
// #pragma once
// #ifndef __HC_H
// #define __HC_H
#include "../LZInWindow.h"
#include "Common/Types.h"
#include "Windows/Defs.h"
#include "../IMatchFinder.h"
namespace HC_NAMESPACE {
typedef UInt32 CIndex;
const UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;
// #define __USE_3_BYTES
#ifdef __USE_3_BYTES
#pragma pack(push, PragmaBinTree)
#pragma pack(push, 1)
struct CIndex
class CMatchFinderHC:
public IMatchFinder,
public IMatchFinderSetCallback,
public CLZInWindow,
public CMyUnknownImp
{
BYTE Data[3];
CIndex(){}
CIndex(UINT32 aValue)
{
Data[0] = aValue & 0xFF;
Data[1] = (aValue >> 8) & 0xFF;
Data[2] = (aValue >> 16) & 0xFF;
}
operator UINT32() const { return (*((const UINT32 *)Data)) & 0xFFFFFF; }
};
const UINT32 kMaxValForNormalize = CIndex(-1);
#pragma pack(pop)
#pragma pack(pop, PragmaBinTree)
#else
typedef UINT32 CIndex;
const UINT32 kMaxValForNormalize = (UINT32(1) << 31) - 1;
#endif
// #define HASH_ARRAY_2
// #ifdef HASH_ARRAY_2
// #define HASH_ARRAY_3
// #else
// #define HASH_ZIP
// #endif
class CInTree: public CLZInWindow
{
UINT32 _cyclicBufferPos;
UINT32 _cyclicBufferSize;
UINT32 _historySize;
UINT32 _matchMaxLen;
UInt32 _cyclicBufferPos;
UInt32 _cyclicBufferSize; // it must be historySize + 1
UInt32 _matchMaxLen;
CIndex *_hash;
#ifdef HASH_ARRAY_2
CIndex *_hash2;
#ifdef HASH_ARRAY_3
CIndex *_hash3;
#endif
#endif
CIndex *_chain;
UInt32 _cutValue;
UINT32 _cutValue;
CMyComPtr<IMatchFinderCallback> m_Callback;
void NormalizeLinks(CIndex *anArray, UINT32 aNumItems, UINT32 aSubValue);
void Normalize();
void FreeThisClassMemory();
void FreeMemory();
MY_UNKNOWN_IMP1(IMatchFinderSetCallback)
STDMETHOD(Init)(ISequentialInStream *inStream);
STDMETHOD_(void, ReleaseStream)();
STDMETHOD(MovePos)();
STDMETHOD_(Byte, GetIndexByte)(Int32 index);
STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);
STDMETHOD_(UInt32, GetNumAvailableBytes)();
STDMETHOD_(const Byte *, GetPointerToCurrentPos)();
STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter);
STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);
STDMETHOD_(void, DummyLongestMatch)();
// IMatchFinderSetCallback
STDMETHOD(SetCallback)(IMatchFinderCallback *callback);
virtual void BeforeMoveBlock();
virtual void AfterMoveBlock();
public:
CInTree();
~CInTree();
HRESULT Create(UINT32 aSizeHistory, UINT32 aKeepAddBufferBefore, UINT32 aMatchMaxLen,
UINT32 aKeepAddBufferAfter, UINT32 _dwSizeReserv = (1<<17));
HRESULT Init(ISequentialInStream *aStream);
void SetCutValue(UINT32 aCutValue) { _cutValue = aCutValue; }
UINT32 GetLongestMatch(UINT32 *aDistances);
void DummyLongestMatch();
HRESULT MovePos()
{
_cyclicBufferPos++;
if (_cyclicBufferPos >= _cyclicBufferSize)
_cyclicBufferPos = 0;
RINOK(CLZInWindow::MovePos());
if (_pos == kMaxValForNormalize)
Normalize();
return S_OK;
}
CMatchFinderHC();
virtual ~CMatchFinderHC();
void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }
};
}
// #endif

View File

@@ -1,12 +1,7 @@
// HC2.h
#pragma once
#ifndef __HC2__H
#define __HC2__H
#undef HC_CLSID
#define HC_CLSID CLSID_CMatchFinderHC2
#ifndef __HC2_H
#define __HC2_H
#undef HC_NAMESPACE
#define HC_NAMESPACE NHC2

View File

@@ -1,20 +1,15 @@
// HC3.h
#pragma once
#ifndef __HC3__H
#define __HC3__H
#undef HC_CLSID
#define HC_CLSID CLSID_CMatchFinderHC3
#ifndef __HC3_H
#define __HC3_H
#undef HC_NAMESPACE
#define HC_NAMESPACE NHC3
#define HASH_ARRAY_2
#include "HCMF.h"
#include "HCMFMain.h"
#include "HC.h"
#include "HCMain.h"
#undef HASH_ARRAY_2

View File

@@ -1,12 +1,7 @@
// HC4.h
#pragma once
#ifndef __HC4__H
#define __HC4__H
#undef HC_CLSID
#define HC_CLSID CLSID_CMatchFinderHC4
#ifndef __HC4_H
#define __HC4_H
#undef HC_NAMESPACE
#define HC_NAMESPACE NHC4
@@ -14,8 +9,8 @@
#define HASH_ARRAY_2
#define HASH_ARRAY_3
#include "HCMF.h"
#include "HCMFMain.h"
#include "HC.h"
#include "HCMain.h"
#undef HASH_ARRAY_2
#undef HASH_ARRAY_3

View File

@@ -1,13 +1,8 @@
// HC4b.h
#pragma once
#ifndef __HC4B__H
#define __HC4B__H
#undef HC_CLSID
#define HC_CLSID CLSID_CMatchFinderHC4b
#undef HC_NAMESPACE
#define HC_NAMESPACE NHC4b
@@ -15,8 +10,8 @@
#define HASH_ARRAY_3
#define HASH_BIG
#include "HCMF.h"
#include "HCMFMain.h"
#include "HC.h"
#include "HCMain.h"
#undef HASH_ARRAY_2
#undef HASH_ARRAY_3

View File

@@ -1,111 +0,0 @@
// HCMF.h
// #pragma once
// #ifndef __HCMF_H
// #define __HCMF_H
#include "Common/MyCom.h"
// #include "../../../Interface/CompressInterface.h"
#include "HC.h"
namespace HC_NAMESPACE {
#undef kIDByte
#undef kIDString
#ifdef HASH_ARRAY_2
#ifdef HASH_ARRAY_3
#ifdef HASH_BIG
#define kIDByte 0x4
#define kIDString TEXT("4b")
#else
#define kIDByte 0x3
#define kIDString TEXT("4")
#endif
#else
#define kIDByte 0x2
#define kIDString TEXT("3")
#endif
#else
#ifdef HASH_ZIP
#define kIDByte 0x0
#define kIDString TEXT("3Z")
#else
#define kIDByte 0x1
#define kIDString TEXT("2")
#endif
#endif
#undef kIDUse3BytesByte
#undef kIDUse3BytesString
#ifdef __USE_3_BYTES
#define kIDUse3BytesByte 0x80
#define kIDUse3BytesString TEXT("T")
#else
#define kIDUse3BytesByte 0x00
#define kIDUse3BytesString TEXT("")
#endif
// #undef kIDStringFull
// #define kIDStringFull TEXT("Compress.MatchFinderHC") kIDString kIDUse3BytesString
// {23170F69-40C1-278C-03XX-0000000000}
DEFINE_GUID(HC_CLSID,
0x23170F69, 0x40C1, 0x278C, 0x03, kIDByte | kIDUse3BytesByte,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
class CInTree2: public CInTree
{
CMyComPtr<IMatchFinderCallback> m_Callback;
virtual void BeforeMoveBlock();
virtual void AfterMoveBlock();
public:
void SetCallback(IMatchFinderCallback *aCallback)
{
m_Callback = aCallback;
}
};
class CMatchFinderHC:
public IMatchFinder,
public IMatchFinderSetCallback,
public CMyUnknownImp
{
MY_UNKNOWN_IMP1(IMatchFinderSetCallback)
STDMETHOD(Init)(ISequentialInStream *aStream);
STDMETHOD_(void, ReleaseStream)();
STDMETHOD(MovePos)();
STDMETHOD_(BYTE, GetIndexByte)(UINT32 anIndex);
STDMETHOD_(UINT32, GetMatchLen)(UINT32 aIndex, UINT32 aBack, UINT32 aLimit);
STDMETHOD_(UINT32, GetNumAvailableBytes)();
STDMETHOD_(const BYTE *, GetPointerToCurrentPos)();
STDMETHOD(Create)(UINT32 aSizeHistory,
UINT32 aKeepAddBufferBefore, UINT32 aMatchMaxLen,
UINT32 aKeepAddBufferAfter);
STDMETHOD_(UINT32, GetLongestMatch)(UINT32 *aDistances);
STDMETHOD_(void, DummyLongestMatch)();
// IMatchFinderSetCallback
STDMETHOD(SetCallback)(IMatchFinderCallback *aCallback);
private:
// UINT32 m_WindowReservSize;
CInTree2 m_MatchFinder;
public:
// CMatchFinderHC(): m_WindowReservSize((1 << 19) + 256) {};
void SetCutValue(UINT32 aCutValue)
{ m_MatchFinder.SetCutValue(aCutValue); }
/*
void SetWindowReservSize(UINT32 aReservWindowSize)
{ m_WindowReservSize = aReservWindowSize; }
*/
};
}
// #endif

View File

@@ -1,78 +0,0 @@
// HCMFMain.h
#include "HCMain.h"
namespace HC_NAMESPACE {
void CInTree2::BeforeMoveBlock()
{
if (m_Callback)
m_Callback->BeforeChangingBufferPos();
CInTree::BeforeMoveBlock();
}
void CInTree2::AfterMoveBlock()
{
if (m_Callback)
m_Callback->AfterChangingBufferPos();
CInTree::AfterMoveBlock();
}
STDMETHODIMP CMatchFinderHC::Init(ISequentialInStream *aStream)
{ return m_MatchFinder.Init(aStream); }
STDMETHODIMP_(void) CMatchFinderHC::ReleaseStream()
{
// m_MatchFinder.ReleaseStream();
}
STDMETHODIMP CMatchFinderHC::MovePos()
{ return m_MatchFinder.MovePos(); }
STDMETHODIMP_(BYTE) CMatchFinderHC::GetIndexByte(UINT32 anIndex)
{ return m_MatchFinder.GetIndexByte(anIndex); }
STDMETHODIMP_(UINT32) CMatchFinderHC::GetMatchLen(UINT32 aIndex,
UINT32 aBack, UINT32 aLimit)
{ return m_MatchFinder.GetMatchLen(aIndex, aBack, aLimit); }
STDMETHODIMP_(UINT32) CMatchFinderHC::GetNumAvailableBytes()
{ return m_MatchFinder.GetNumAvailableBytes(); }
STDMETHODIMP CMatchFinderHC::Create(UINT32 aSizeHistory,
UINT32 aKeepAddBufferBefore, UINT32 aMatchMaxLen,
UINT32 aKeepAddBufferAfter)
{
UINT32 aWindowReservSize = (aSizeHistory + aKeepAddBufferBefore +
aMatchMaxLen + aKeepAddBufferAfter) / 2 + 256;
try
{
return m_MatchFinder.Create(aSizeHistory, aKeepAddBufferBefore, aMatchMaxLen,
aKeepAddBufferAfter, aWindowReservSize);
}
catch(...)
{
return E_OUTOFMEMORY;
}
}
STDMETHODIMP_(UINT32) CMatchFinderHC::GetLongestMatch(UINT32 *aDistances)
{ return m_MatchFinder.GetLongestMatch(aDistances); }
STDMETHODIMP_(void) CMatchFinderHC::DummyLongestMatch()
{ m_MatchFinder.DummyLongestMatch(); }
STDMETHODIMP_(const BYTE *) CMatchFinderHC::GetPointerToCurrentPos()
{
return m_MatchFinder.GetPointerToCurrentPos();
}
// IMatchFinderSetCallback
STDMETHODIMP CMatchFinderHC::SetCallback(IMatchFinderCallback *aCallback)
{
m_MatchFinder.SetCallback(aCallback);
return S_OK;
}
}

View File

@@ -1,436 +1,350 @@
// HC.h
// #include "StdAfx.h"
// #include "BinTree.h"
#include "Common/NewHandler.h"
#include "Common/Defs.h"
#include "Common/CRC.h"
#include "../../../../Common/Defs.h"
#include "../../../../Common/CRC.h"
#include "../../../../Common/Alloc.h"
namespace HC_NAMESPACE {
#ifdef HASH_ARRAY_2
static const UINT32 kHash2Size = 1 << 10;
static const UInt32 kHash2Size = 1 << 10;
#ifdef HASH_ARRAY_3
static const UINT32 kNumHashDirectBytes = 0;
static const UINT32 kNumHashBytes = 4;
static const UINT32 kHash3Size = 1 << 18;
static const UInt32 kNumHashDirectBytes = 0;
static const UInt32 kNumHashBytes = 4;
static const UInt32 kHash3Size = 1 << 18;
#ifdef HASH_BIG
static const UINT32 kHashSize = 1 << 23;
static const UInt32 kHashSize = 1 << 23;
#else
static const UINT32 kHashSize = 1 << 20;
static const UInt32 kHashSize = 1 << 20;
#endif
#else
static const UINT32 kNumHashBytes = 3;
// static const UINT32 kNumHashDirectBytes = 3;
// static const UINT32 kHashSize = 1 << (8 * kNumHashBytes);
static const UINT32 kNumHashDirectBytes = 0;
static const UINT32 kHashSize = 1 << (16);
static const UInt32 kNumHashDirectBytes = 0;
static const UInt32 kNumHashBytes = 3;
static const UInt32 kHashSize = 1 << (16);
#endif
#else
#ifdef HASH_ZIP
static const UINT32 kNumHashDirectBytes = 0;
static const UINT32 kNumHashBytes = 3;
static const UINT32 kHashSize = 1 << 16;
static const UInt32 kNumHashDirectBytes = 0;
static const UInt32 kNumHashBytes = 3;
static const UInt32 kHashSize = 1 << 16;
#else
static const UINT32 kNumHashDirectBytes = 2;
static const UINT32 kNumHashBytes = 2;
static const UINT32 kHashSize = 1 << (8 * kNumHashBytes);
#define THERE_ARE_DIRECT_HASH_BYTES
static const UInt32 kNumHashDirectBytes = 2;
static const UInt32 kNumHashBytes = 2;
static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);
#endif
#endif
static const UInt32 kHashSizeSum = kHashSize
#ifdef HASH_ARRAY_2
+ kHash2Size
#ifdef HASH_ARRAY_3
+ kHash3Size
#endif
#endif
;
CInTree::CInTree():
#ifdef HASH_ARRAY_2
_hash2(0),
#ifdef HASH_ARRAY_3
_hash3(0),
#endif
#endif
#ifdef HASH_ARRAY_2
static const UInt32 kHash2Offset = kHashSize;
#ifdef HASH_ARRAY_3
static const UInt32 kHash3Offset = kHashSize + kHash2Size;
#endif
#endif
CMatchFinderHC::CMatchFinderHC():
_hash(0),
_chain(0),
_cutValue(16)
{
}
void CInTree::FreeMemory()
void CMatchFinderHC::FreeThisClassMemory()
{
#ifdef WIN32
if (_chain != 0)
VirtualFree(_chain, 0, MEM_RELEASE);
if (_hash != 0)
VirtualFree(_hash, 0, MEM_RELEASE);
#else
delete []_chain;
delete []_hash;
#endif
_chain = 0;
BigFree(_hash);
_hash = 0;
}
void CMatchFinderHC::FreeMemory()
{
FreeThisClassMemory();
CLZInWindow::Free();
}
CInTree::~CInTree()
CMatchFinderHC::~CMatchFinderHC()
{
FreeMemory();
}
HRESULT CInTree::Create(UINT32 aSizeHistory, UINT32 aKeepAddBufferBefore,
UINT32 aMatchMaxLen, UINT32 aKeepAddBufferAfter, UINT32 aSizeReserv)
STDMETHODIMP CMatchFinderHC::Create(UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter)
{
FreeMemory();
try
UInt32 sizeReserv = (historySize + keepAddBufferBefore +
matchMaxLen + keepAddBufferAfter) / 2 + 256;
if (CLZInWindow::Create(historySize + keepAddBufferBefore,
matchMaxLen + keepAddBufferAfter, sizeReserv))
{
CLZInWindow::Create(aSizeHistory + aKeepAddBufferBefore,
aMatchMaxLen + aKeepAddBufferAfter, aSizeReserv);
if (_blockSize + 256 > kMaxValForNormalize)
if (historySize + 256 > kMaxValForNormalize)
{
FreeMemory();
return E_INVALIDARG;
_historySize = aSizeHistory;
_matchMaxLen = aMatchMaxLen;
_cyclicBufferSize = aSizeHistory + 1;
UINT32 aSize = kHashSize;
#ifdef HASH_ARRAY_2
aSize += kHash2Size;
#ifdef HASH_ARRAY_3
aSize += kHash3Size;
#endif
#endif
#ifdef WIN32
_chain = (CIndex *)::VirtualAlloc(0, (_cyclicBufferSize + 1) * sizeof(CIndex), MEM_COMMIT, PAGE_READWRITE);
if (_chain == 0)
throw CNewException();
_hash = (CIndex *)::VirtualAlloc(0, (aSize + 1) * sizeof(CIndex), MEM_COMMIT, PAGE_READWRITE);
if (_hash == 0)
throw CNewException();
#else
_chain = new CIndex[_cyclicBufferSize + 1];
_hash = new CIndex[aSize + 1];
#endif
// m_RightBase = &m_LeftBase[_blockSize];
// _hash = &m_RightBase[_blockSize];
#ifdef HASH_ARRAY_2
_hash2 = &_hash[kHashSize];
#ifdef HASH_ARRAY_3
_hash3 = &_hash2[kHash2Size];
#endif
#endif
return S_OK;
}
catch(...)
{
FreeMemory();
return E_OUTOFMEMORY;
}
_matchMaxLen = matchMaxLen;
UInt32 newCyclicBufferSize = historySize + 1;
if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize)
return S_OK;
FreeThisClassMemory();
_cyclicBufferSize = newCyclicBufferSize; // don't change it
_hash = (CIndex *)BigAlloc((kHashSizeSum + _cyclicBufferSize) * sizeof(CIndex));
if (_hash != 0)
return S_OK;
}
FreeMemory();
return E_OUTOFMEMORY;
}
static const UINT32 kEmptyHashValue = 0;
static const UInt32 kEmptyHashValue = 0;
HRESULT CInTree::Init(ISequentialInStream *aStream)
STDMETHODIMP CMatchFinderHC::Init(ISequentialInStream *stream)
{
RINOK(CLZInWindow::Init(aStream));
int i;
for(i = 0; i < kHashSize; i++)
RINOK(CLZInWindow::Init(stream));
for(UInt32 i = 0; i < kHashSizeSum; i++)
_hash[i] = kEmptyHashValue;
#ifdef HASH_ARRAY_2
for(i = 0; i < kHash2Size; i++)
_hash2[i] = kEmptyHashValue;
#ifdef HASH_ARRAY_3
for(i = 0; i < kHash3Size; i++)
_hash3[i] = kEmptyHashValue;
#endif
#endif
_cyclicBufferPos = 0;
ReduceOffsets(0 - 1);
ReduceOffsets(-1);
return S_OK;
}
STDMETHODIMP_(void) CMatchFinderHC::ReleaseStream()
{
// ReleaseStream();
}
#ifdef HASH_ARRAY_2
#ifdef HASH_ARRAY_3
inline UINT32 Hash(const BYTE *pointer, UINT32 &hash2Value, UINT32 &aHash3Value)
inline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value, UInt32 &hash3Value)
{
UINT32 temp = CCRC::Table[pointer[0]] ^ pointer[1];
UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];
hash2Value = temp & (kHash2Size - 1);
aHash3Value = (temp ^ (UINT32(pointer[2]) << 8)) & (kHash3Size - 1);
return (temp ^ (UINT32(pointer[2]) << 8) ^ (CCRC::Table[pointer[3]] << 5)) &
hash3Value = (temp ^ (UInt32(pointer[2]) << 8)) & (kHash3Size - 1);
return (temp ^ (UInt32(pointer[2]) << 8) ^ (CCRC::Table[pointer[3]] << 5)) &
(kHashSize - 1);
}
#else // no HASH_ARRAY_3
inline UINT32 Hash(const BYTE *pointer, UINT32 &hash2Value)
inline UInt32 Hash(const Byte *pointer, UInt32 &hash2Value)
{
UINT32 temp = CCRC::Table[pointer[0]] ^ pointer[1];
UInt32 temp = CCRC::Table[pointer[0]] ^ pointer[1];
hash2Value = temp & (kHash2Size - 1);
return (temp ^ (UINT32(pointer[2]) << 8)) & (kHashSize - 1);;
return (temp ^ (UInt32(pointer[2]) << 8)) & (kHashSize - 1);;
}
#endif // HASH_ARRAY_3
#else // no HASH_ARRAY_2
#ifdef HASH_ZIP
inline UINT32 Hash(const BYTE *pointer)
inline UInt32 Hash(const Byte *pointer)
{
return ((UINT32(pointer[0]) << 8) ^
return ((UInt32(pointer[0]) << 8) ^
CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);
}
#else // no HASH_ZIP
inline UINT32 Hash(const BYTE *pointer)
inline UInt32 Hash(const Byte *pointer)
{
return pointer[0] ^ (UINT32(pointer[1]) << 8);
return pointer[0] ^ (UInt32(pointer[1]) << 8);
}
#endif // HASH_ZIP
#endif // HASH_ARRAY_2
UINT32 CInTree::GetLongestMatch(UINT32 *aDistances)
STDMETHODIMP_(UInt32) CMatchFinderHC::GetLongestMatch(UInt32 *distances)
{
UINT32 aCurrentLimit;
UInt32 lenLimit;
if (_pos + _matchMaxLen <= _streamPos)
aCurrentLimit = _matchMaxLen;
lenLimit = _matchMaxLen;
else
{
aCurrentLimit = _streamPos - _pos;
if(aCurrentLimit < kNumHashBytes)
lenLimit = _streamPos - _pos;
if(lenLimit < kNumHashBytes)
return 0;
}
UINT32 aMatchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;
BYTE *aCur = _buffer + _pos;
UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
Byte *cur = _buffer + _pos;
UINT32 aMatchHashLenMax = 0;
UInt32 maxLen = 0;
#ifdef HASH_ARRAY_2
UINT32 hash2Value;
UInt32 hash2Value;
#ifdef HASH_ARRAY_3
UINT32 aHash3Value;
UINT32 hashValue = Hash(aCur, hash2Value, aHash3Value);
#else // no HASH_ARRAY_3
UINT32 hashValue = Hash(aCur, hash2Value);
#endif // HASH_ARRAY_3
#else // no HASH_ARRAY_2
UINT32 hashValue = Hash(aCur);
#endif
#ifdef HASH_ARRAY_2
UINT32 aCurMatch2 = _hash2[hash2Value];
_hash2[hash2Value] = _pos;
bool aMatchLen2Exist = false;
UINT32 aLen2Distance = 0;
if(aCurMatch2 >= aMatchMinPos)
{
if (_buffer[aCurMatch2] == aCur[0])
{
aLen2Distance = _pos - aCurMatch2 - 1;
aMatchHashLenMax = 2;
aMatchLen2Exist = true;
}
}
#ifdef HASH_ARRAY_3
UINT32 aCurMatch3 = _hash3[aHash3Value];
_hash3[aHash3Value] = _pos;
UINT32 aMatchLen3Exist = false;
UINT32 aLen3Distance = 0;
if(aCurMatch3 >= aMatchMinPos)
{
if (_buffer[aCurMatch3] == aCur[0])
{
aLen3Distance = _pos - aCurMatch3 - 1;
aMatchHashLenMax = 3;
aMatchLen3Exist = true;
if (aMatchLen2Exist)
{
if (aLen3Distance < aLen2Distance)
aLen2Distance = aLen3Distance;
}
else
{
aLen2Distance = aLen3Distance;
aMatchLen2Exist = true;
}
}
}
#endif
#endif
UINT32 aCurMatch = _hash[hashValue];
_hash[hashValue] = _pos;
if(aCurMatch < aMatchMinPos)
{
_chain[_cyclicBufferPos] = kEmptyHashValue;
#ifdef HASH_ARRAY_2
aDistances[2] = aLen2Distance;
#ifdef HASH_ARRAY_3
aDistances[3] = aLen3Distance;
#endif
#endif
return aMatchHashLenMax;
}
_chain[_cyclicBufferPos] = aCurMatch;
#ifdef HASH_ARRAY_2
#ifndef HASH_ARRAY_3
if (aMatchLen2Exist)
aDistances[2] = aLen2Distance;
else
if (kNumHashDirectBytes >= 2)
aDistances[2] = _pos - aCurMatch - 1;
#endif
#endif
UINT32 aMax, aMinSame;
aMax = aMinSame = kNumHashDirectBytes;
aDistances[aMax] = _pos - aCurMatch - 1;
for(UINT32 aCount = _cutValue; aCount > 0; aCount--)
{
BYTE *pby1 = _buffer + aCurMatch;
UINT32 aCurrentLen;
for(aCurrentLen = aMinSame; aCurrentLen < aCurrentLimit; aCurrentLen++/*, dwComps++*/)
if (pby1[aCurrentLen] != aCur[aCurrentLen])
break;
if (aCurrentLen > aMax)
{
UINT32 dwBack = _pos - aCurMatch - 1;
for(UINT32 dwLen = aMax + 1; dwLen <= aCurrentLen; dwLen++)
aDistances[dwLen] = dwBack;
aMax = aCurrentLen;
}
if(aCurrentLen == aCurrentLimit)
break;
UINT32 aDelta = _pos - aCurMatch;
UINT32 aCyclicPos = (aDelta <= _cyclicBufferPos) ?
(_cyclicBufferPos - aDelta):
(_cyclicBufferPos - aDelta + _cyclicBufferSize);
aCurMatch = _chain[aCyclicPos];
if(aCurMatch < aMatchMinPos)
break;
}
#ifdef HASH_ARRAY_2
if (aMatchLen2Exist)
{
if (aMax < 2)
{
aDistances[2] = aLen2Distance;
aMax = 2;
}
else if (aLen2Distance < aDistances[2])
aDistances[2] = aLen2Distance;
}
#ifdef HASH_ARRAY_3
if (aMatchLen3Exist)
{
if (aMax < 3)
{
aDistances[3] = aLen3Distance;
aMax = 3;
}
else if (aLen3Distance < aDistances[3])
aDistances[3] = aLen3Distance;
}
#endif
#endif
return aMax;
}
void CInTree::DummyLongestMatch()
{
UINT32 aCurrentLimit;
if (_pos + _matchMaxLen <= _streamPos)
aCurrentLimit = _matchMaxLen;
else
{
aCurrentLimit = _streamPos - _pos;
if(aCurrentLimit < kNumHashBytes)
return;
}
UINT32 aMatchMinPos = (_pos > _historySize) ? (_pos - _historySize) : 1;
BYTE *aCur = _buffer + _pos;
#ifdef HASH_ARRAY_2
UINT32 hash2Value;
#ifdef HASH_ARRAY_3
UINT32 aHash3Value;
UINT32 hashValue = Hash(aCur, hash2Value, aHash3Value);
_hash3[aHash3Value] = _pos;
UInt32 hash3Value;
UInt32 hashValue = Hash(cur, hash2Value, hash3Value);
#else
UINT32 hashValue = Hash(aCur, hash2Value);
UInt32 hashValue = Hash(cur, hash2Value);
#endif
_hash2[hash2Value] = _pos;
#else // no hash
UINT32 hashValue = Hash(aCur);
#else
UInt32 hashValue = Hash(cur);
#endif
UINT32 aCurMatch = _hash[hashValue];
_hash[hashValue] = _pos;
if(aCurMatch < aMatchMinPos)
{
_chain[_cyclicBufferPos] = kEmptyHashValue;
return;
}
_chain[_cyclicBufferPos] = aCurMatch;
}
void CInTree::NormalizeLinks(CIndex *anArray, UINT32 aNumItems, UINT32 aSubValue)
{
for (UINT32 i = 0; i < aNumItems; i++)
{
UINT32 aValue = anArray[i];
if (aValue <= aSubValue)
aValue = kEmptyHashValue;
else
aValue -= aSubValue;
anArray[i] = aValue;
}
}
void CInTree::Normalize()
{
UINT32 aStartItem = _pos - _historySize;
UINT32 aSubValue = aStartItem - 1;
// NormalizeLinks(_chain + aStartItem, _historySize, aSubValue);
NormalizeLinks(_chain, _cyclicBufferSize, aSubValue);
NormalizeLinks(_hash, kHashSize, aSubValue);
#ifdef HASH_ARRAY_2
NormalizeLinks(_hash2, kHash2Size, aSubValue);
UInt32 curMatch2 = _hash[kHash2Offset + hash2Value];
_hash[kHash2Offset + hash2Value] = _pos;
distances[2] = 0xFFFFFFFF;
if(curMatch2 > matchMinPos)
if (_buffer[curMatch2] == cur[0])
{
distances[2] = _pos - curMatch2 - 1;
maxLen = 2;
}
#ifdef HASH_ARRAY_3
NormalizeLinks(_hash3, kHash3Size, aSubValue);
UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];
_hash[kHash3Offset + hash3Value] = _pos;
distances[3] = 0xFFFFFFFF;
if(curMatch3 > matchMinPos)
if (_buffer[curMatch3] == cur[0])
{
distances[3] = _pos - curMatch3 - 1;
maxLen = 3;
}
#endif
#endif
ReduceOffsets(aSubValue);
UInt32 curMatch = _hash[hashValue];
_hash[hashValue] = _pos;
CIndex *chain = _hash + kHashSizeSum;
chain[_cyclicBufferPos] = curMatch;
distances[kNumHashBytes] = 0xFFFFFFFF;
#ifdef THERE_ARE_DIRECT_HASH_BYTES
if (lenLimit == kNumHashDirectBytes)
{
if(curMatch > matchMinPos)
while (maxLen < kNumHashDirectBytes)
distances[++maxLen] = _pos - curMatch - 1;
}
else
#endif
{
UInt32 count = _cutValue;
do
{
if(curMatch <= matchMinPos)
break;
Byte *pby1 = _buffer + curMatch;
UInt32 currentLen = kNumHashDirectBytes;
do
{
if (pby1[currentLen] != cur[currentLen])
break;
}
while(++currentLen != lenLimit);
UInt32 delta = _pos - curMatch;
while (maxLen < currentLen)
distances[++maxLen] = delta - 1;
if(currentLen == lenLimit)
break;
UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?
(_cyclicBufferPos - delta):
(_cyclicBufferPos - delta + _cyclicBufferSize);
curMatch = chain[cyclicPos];
}
while(--count != 0);
}
#ifdef HASH_ARRAY_2
#ifdef HASH_ARRAY_3
if (distances[4] < distances[3])
distances[3] = distances[4];
#endif
if (distances[3] < distances[2])
distances[2] = distances[3];
#endif
return maxLen;
}
STDMETHODIMP_(void) CMatchFinderHC::DummyLongestMatch()
{
if (_streamPos - _pos < kNumHashBytes)
return;
Byte *cur = _buffer + _pos;
#ifdef HASH_ARRAY_2
UInt32 hash2Value;
#ifdef HASH_ARRAY_3
UInt32 hash3Value;
UInt32 hashValue = Hash(cur, hash2Value, hash3Value);
_hash[kHash3Offset + hash3Value] = _pos;
#else
UInt32 hashValue = Hash(cur, hash2Value);
#endif
_hash[kHash2Offset + hash2Value] = _pos;
#else
UInt32 hashValue = Hash(cur);
#endif
_hash[kHashSizeSum + _cyclicBufferPos] = _hash[hashValue];
_hash[hashValue] = _pos;
}
void CMatchFinderHC::Normalize()
{
UInt32 subValue = _pos - _cyclicBufferSize;
CIndex *items = _hash;
UInt32 numItems = kHashSizeSum + _cyclicBufferSize;
for (UInt32 i = 0; i < numItems; i++)
{
UInt32 value = items[i];
if (value <= subValue)
value = kEmptyHashValue;
else
value -= subValue;
items[i] = value;
}
ReduceOffsets(subValue);
}
STDMETHODIMP CMatchFinderHC::MovePos()
{
if (++_cyclicBufferPos == _cyclicBufferSize)
_cyclicBufferPos = 0;
RINOK(CLZInWindow::MovePos());
if (_pos == kMaxValForNormalize)
Normalize();
return S_OK;
}
STDMETHODIMP_(Byte) CMatchFinderHC::GetIndexByte(Int32 index)
{ return CLZInWindow::GetIndexByte(index); }
STDMETHODIMP_(UInt32) CMatchFinderHC::GetMatchLen(Int32 index,
UInt32 back, UInt32 limit)
{ return CLZInWindow::GetMatchLen(index, back, limit); }
STDMETHODIMP_(UInt32) CMatchFinderHC::GetNumAvailableBytes()
{ return CLZInWindow::GetNumAvailableBytes(); }
STDMETHODIMP_(const Byte *) CMatchFinderHC::GetPointerToCurrentPos()
{ return CLZInWindow::GetPointerToCurrentPos(); }
// IMatchFinderSetCallback
STDMETHODIMP CMatchFinderHC::SetCallback(IMatchFinderCallback *callback)
{
m_Callback = callback;
return S_OK;
}
void CMatchFinderHC::BeforeMoveBlock()
{
if (m_Callback)
m_Callback->BeforeChangingBufferPos();
CLZInWindow::BeforeMoveBlock();
}
void CMatchFinderHC::AfterMoveBlock()
{
if (m_Callback)
m_Callback->AfterChangingBufferPos();
CLZInWindow::AfterMoveBlock();
}
}

View File

@@ -1,7 +1,5 @@
// MatchFinders/IMatchFinder.h
// #pragma once
#ifndef __IMATCHFINDER_H
#define __IMATCHFINDER_H
@@ -14,10 +12,10 @@ IInWindowStream: public IUnknown
STDMETHOD(Init)(ISequentialInStream *inStream) PURE;
STDMETHOD_(void, ReleaseStream)() PURE;
STDMETHOD(MovePos)() PURE;
STDMETHOD_(BYTE, GetIndexByte)(UINT32 index) PURE;
STDMETHOD_(UINT32, GetMatchLen)(UINT32 index, UINT32 distance, UINT32 limit) PURE;
STDMETHOD_(UINT32, GetNumAvailableBytes)() PURE;
STDMETHOD_(const BYTE *, GetPointerToCurrentPos)() PURE;
STDMETHOD_(Byte, GetIndexByte)(Int32 index) PURE;
STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit) PURE;
STDMETHOD_(UInt32, GetNumAvailableBytes)() PURE;
STDMETHOD_(const Byte *, GetPointerToCurrentPos)() PURE;
};
// {23170F69-40C1-278A-0000-000200020000}
@@ -26,9 +24,9 @@ DEFINE_GUID(IID_IMatchFinder,
MIDL_INTERFACE("23170F69-40C1-278A-0000-000200020000")
IMatchFinder: public IInWindowStream
{
STDMETHOD(Create)(UINT32 historySize, UINT32 keepAddBufferBefore,
UINT32 matchMaxLen, UINT32 keepAddBufferAfter) PURE;
STDMETHOD_(UINT32, GetLongestMatch)(UINT32 *distances) PURE;
STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter) PURE;
STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances) PURE;
STDMETHOD_(void, DummyLongestMatch)() PURE;
};

View File

@@ -4,27 +4,28 @@
#include "LZInWindow.h"
#include "../../../Common/MyCom.h"
CLZInWindow::~CLZInWindow()
{
Free();
}
#include "../../../Common/Alloc.h"
void CLZInWindow::Free()
{
delete []_bufferBase;
::BigFree(_bufferBase);
_bufferBase = 0;
}
void CLZInWindow::Create(UINT32 keepSizeBefore, UINT32 keepSizeAfter, UINT32 keepSizeReserv)
bool CLZInWindow::Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)
{
_keepSizeBefore = keepSizeBefore;
_keepSizeAfter = keepSizeAfter;
_keepSizeReserv = keepSizeReserv;
_blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;
Free();
_bufferBase = new BYTE[_blockSize];
UInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;
if (_bufferBase == 0 || _blockSize != blockSize)
{
Free();
_blockSize = blockSize;
_bufferBase = (Byte *)::BigAlloc(_blockSize);
}
_pointerToLastSafePosition = _bufferBase + _blockSize - keepSizeAfter;
return (_bufferBase != 0);
}
@@ -64,17 +65,17 @@ HRESULT CLZInWindow::ReadBlock()
return S_OK;
while(true)
{
UINT32 size = (_bufferBase + _blockSize) - (_buffer + _streamPos);
UInt32 size = UInt32(_bufferBase - _buffer) + _blockSize - _streamPos;
if(size == 0)
return S_OK;
UINT32 numReadBytes;
UInt32 numReadBytes;
RINOK(_stream->ReadPart(_buffer + _streamPos, size, &numReadBytes));
if(numReadBytes == 0)
{
_posLimit = _streamPos;
const BYTE *pointerToPostion = _buffer + _posLimit;
const Byte *pointerToPostion = _buffer + _posLimit;
if(pointerToPostion > _pointerToLastSafePosition)
_posLimit = _pointerToLastSafePosition - _buffer;
_posLimit = (UInt32)(_pointerToLastSafePosition - _buffer);
_streamEndWasReached = true;
return S_OK;
}
@@ -90,8 +91,8 @@ HRESULT CLZInWindow::ReadBlock()
void CLZInWindow::MoveBlock()
{
BeforeMoveBlock();
UINT32 offset = (_buffer + _pos - _keepSizeBefore) - _bufferBase;
UINT32 numBytes = (_buffer + _streamPos) - (_bufferBase + offset);
UInt32 offset = UInt32(_buffer - _bufferBase) + _pos - _keepSizeBefore;
UInt32 numBytes = UInt32(_buffer - _bufferBase) + _streamPos - offset;
memmove(_bufferBase, _bufferBase + offset, numBytes);
_buffer -= offset;
AfterMoveBlock();

View File

@@ -1,7 +1,5 @@
// LZInWindow.h
// #pragma once
#ifndef __LZ_IN_WINDOW_H
#define __LZ_IN_WINDOW_H
@@ -9,19 +7,19 @@
class CLZInWindow
{
BYTE *_bufferBase; // pointer to buffer with data
Byte *_bufferBase; // pointer to buffer with data
ISequentialInStream *_stream;
UINT32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done
UInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done
bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream
const BYTE *_pointerToLastSafePosition;
const Byte *_pointerToLastSafePosition;
protected:
BYTE *_buffer; // Pointer to virtual Buffer begin
UINT32 _blockSize; // Size of Allocated memory block
UINT32 _pos; // offset (from _buffer) of curent byte
UINT32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos
UINT32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos
UINT32 _keepSizeReserv; // how many BYTEs must be kept as reserv
UINT32 _streamPos; // offset (from _buffer) of first not read byte from Stream
Byte *_buffer; // Pointer to virtual Buffer begin
UInt32 _blockSize; // Size of Allocated memory block
UInt32 _pos; // offset (from _buffer) of curent byte
UInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos
UInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos
UInt32 _keepSizeReserv; // how many BYTEs must be kept as reserv
UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream
virtual void BeforeMoveBlock() {};
virtual void AfterMoveBlock() {};
@@ -30,23 +28,24 @@ protected:
void Free();
public:
CLZInWindow(): _bufferBase(0) {}
~CLZInWindow();
void Create(UINT32 keepSizeBefore, UINT32 keepSizeAfter,
UINT32 keepSizeReserv = (1<<17));
virtual ~CLZInWindow() { Free(); }
bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter,
UInt32 keepSizeReserv = (1<<17));
HRESULT Init(ISequentialInStream *stream);
// void ReleaseStream();
BYTE *GetBuffer() const { return _buffer; }
Byte *GetBuffer() const { return _buffer; }
const BYTE *GetPointerToCurrentPos() const { return _buffer + _pos; }
const Byte *GetPointerToCurrentPos() const { return _buffer + _pos; }
HRESULT MovePos()
{
_pos++;
if (_pos > _posLimit)
{
const BYTE *pointerToPostion = _buffer + _pos;
const Byte *pointerToPostion = _buffer + _pos;
if(pointerToPostion > _pointerToLastSafePosition)
MoveBlock();
return ReadBlock();
@@ -54,29 +53,25 @@ public:
else
return S_OK;
}
// BYTE GetCurrentByte()const;
BYTE GetIndexByte(UINT32 index)const
{ return _buffer[_pos + index]; }
// UINT32 GetCurPos()const { return _pos;};
// BYTE *GetBufferBeg()const { return _buffer;};
Byte GetIndexByte(Int32 index)const
{ return _buffer[(size_t)_pos + index]; }
// index + limit have not to exceed _keepSizeAfter;
UINT32 GetMatchLen(UINT32 index, UINT32 back, UINT32 limit) const
UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const
{
if(_streamEndWasReached)
if ((_pos + index) + limit > _streamPos)
limit = _streamPos - (_pos + index);
back++;
BYTE *pby = _buffer + _pos + index;
UINT32 i;
for(i = 0; i < limit && pby[i] == pby[i - back]; i++);
distance++;
Byte *pby = _buffer + (size_t)_pos + index;
UInt32 i;
for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);
return i;
}
UINT32 GetNumAvailableBytes() const { return _streamPos - _pos; }
UInt32 GetNumAvailableBytes() const { return _streamPos - _pos; }
void ReduceOffsets(UINT32 subValue)
void ReduceOffsets(Int32 subValue)
{
_buffer += subValue;
_posLimit -= subValue;

View File

@@ -2,51 +2,52 @@
#include "StdAfx.h"
#include "../../../Common/Alloc.h"
#include "LZOutWindow.h"
void CLZOutWindow::Create(UINT32 windowSize)
bool CLZOutWindow::Create(UInt32 windowSize)
{
const UInt32 kMinBlockSize = 1;
if (windowSize < kMinBlockSize)
windowSize = kMinBlockSize;
if (_buffer != 0 && _windowSize == windowSize)
return true;
// It's here to allow Solid decoding / and calling Create for RAR
_pos = 0;
_streamPos = 0;
UINT32 newBlockSize = windowSize;
const UINT32 kMinBlockSize = 1;
if (newBlockSize < kMinBlockSize)
newBlockSize = kMinBlockSize;
if (_buffer != 0 && _windowSize == newBlockSize)
return;
delete []_buffer;
_buffer = 0;
_windowSize = newBlockSize;
_buffer = new BYTE[_windowSize];
}
CLZOutWindow::~CLZOutWindow()
{
// ReleaseStream();
delete []_buffer;
}
/*
void CLZOutWindow::SetWindowSize(UINT32 windowSize)
{
Free();
_windowSize = windowSize;
_buffer = (Byte *)::BigAlloc(windowSize);
return (_buffer != 0);
}
*/
void CLZOutWindow::Init(ISequentialOutStream *stream, bool solid)
void CLZOutWindow::Free()
{
// ReleaseStream();
_stream = stream;
// _stream->AddRef();
::BigFree(_buffer);
_buffer = 0;
}
void CLZOutWindow::SetStream(ISequentialOutStream *stream)
{
ReleaseStream();
_stream = stream;
_stream->AddRef();
}
void CLZOutWindow::Init(bool solid)
{
if(!solid)
{
_streamPos = 0;
_pos = 0;
}
#ifdef _NO_EXCEPTIONS
ErrorCode = S_OK;
#endif
}
/*
void CLZOutWindow::ReleaseStream()
{
if(_stream != 0)
@@ -56,26 +57,37 @@ void CLZOutWindow::ReleaseStream()
_stream = 0;
}
}
*/
void CLZOutWindow::FlushWithCheck()
{
HRESULT result = Flush();
#ifdef _NO_EXCEPTIONS
ErrorCode = result;
#else
if (result != S_OK)
throw CLZOutWindowException(result);
#endif
}
HRESULT CLZOutWindow::Flush()
{
UINT32 size = _pos - _streamPos;
UInt32 size = _pos - _streamPos;
if(size == 0)
return S_OK;
UINT32 processedSize;
HRESULT result = _stream->Write(_buffer + _streamPos, size, &processedSize);
if (result != S_OK)
return result;
if (size != processedSize)
return E_FAIL;
#ifdef _NO_EXCEPTIONS
if (ErrorCode != S_OK)
return ErrorCode;
#endif
if(_stream != 0)
{
UInt32 processedSize;
HRESULT result = _stream->Write(_buffer + _streamPos, size, &processedSize);
if (result != S_OK)
return result;
if (size != processedSize)
return E_FAIL;
}
if (_pos >= _windowSize)
_pos = 0;
_streamPos = _pos;

View File

@@ -1,78 +1,72 @@
// LZOutWindow.h
// #pragma once
#ifndef __LZ_OUT_WINDOW_H
#define __LZ_OUT_WINDOW_H
#include "../../IStream.h"
// m_KeepSizeBefore: how mach BYTEs must be in buffer before _pos;
// m_KeepSizeAfter: how mach BYTEs must be in buffer after _pos;
// m_KeepSizeReserv: how mach BYTEs must be in buffer for Moving Reserv;
// must be >= aKeepSizeAfter; // test it
#ifndef _NO_EXCEPTIONS
class CLZOutWindowException
{
public:
HRESULT ErrorCode;
CLZOutWindowException(HRESULT errorCode): ErrorCode(errorCode) {}
};
#endif
class CLZOutWindow
{
BYTE *_buffer;
UINT32 _pos;
UINT32 _windowSize;
UINT32 _streamPos;
Byte *_buffer;
UInt32 _pos;
UInt32 _windowSize;
UInt32 _streamPos;
ISequentialOutStream *_stream;
void FlushWithCheck();
public:
#ifdef _NO_EXCEPTIONS
HRESULT ErrorCode;
#endif
void Free();
CLZOutWindow(): _buffer(0), _stream(0) {}
~CLZOutWindow();
void Create(UINT32 windowSize);
bool IsCreated() const { return _buffer != 0; }
void Init(ISequentialOutStream *stream, bool solid = false);
HRESULT Flush();
// void ReleaseStream();
~CLZOutWindow() { Free(); /* ReleaseStream(); */ }
bool Create(UInt32 windowSize);
// UINT32 GetCurPos() const { return _pos; }
// const BYTE *GetPointerToCurrentPos() const { return _buffer + _pos;};
void CopyBackBlock(UINT32 distance, UINT32 len)
void SetStream(ISequentialOutStream *stream);
void Init(bool solid = false);
HRESULT Flush();
void ReleaseStream();
void CopyBlock(UInt32 distance, UInt32 len)
{
UINT32 pos = _pos - distance - 1;
if (pos >= _windowSize)
pos += _windowSize;
for(; len > 0; len--)
{
if (pos >= _windowSize)
pos = 0;
_buffer[_pos++] = _buffer[pos++];
if (_pos >= _windowSize)
FlushWithCheck();
// PutOneByte(GetOneByte(0 - distance));
}
UInt32 pos = _pos - distance - 1;
if (pos >= _windowSize)
pos += _windowSize;
for(; len > 0; len--)
{
if (pos >= _windowSize)
pos = 0;
_buffer[_pos++] = _buffer[pos++];
if (_pos >= _windowSize)
FlushWithCheck();
// PutOneByte(GetOneByte(distance));
}
}
void PutOneByte(BYTE b)
void PutByte(Byte b)
{
_buffer[_pos++] = b;
if (_pos >= _windowSize)
FlushWithCheck();
_buffer[_pos++] = b;
if (_pos >= _windowSize)
FlushWithCheck();
}
BYTE GetOneByte(UINT32 index) const
Byte GetByte(UInt32 distance) const
{
UINT32 pos = _pos + index;
if (pos >= _windowSize)
pos += _windowSize;
return _buffer[pos];
UInt32 pos = _pos - distance - 1;
if (pos >= _windowSize)
pos += _windowSize;
return _buffer[pos];
}
// BYTE *GetBuffer() const { return _buffer; }
};
#endif

View File

@@ -1,7 +1,9 @@
// MT_MF.cpp
// MT.cpp
#include "StdAfx.h"
#include "../../../../Common/Alloc.h"
#include "MT.h"
class CMatchFinderCallback:
@@ -14,7 +16,7 @@ class CMatchFinderCallback:
STDMETHOD(AfterChangingBufferPos)();
public:
CMatchFinderMT *m_MatchFinderMT;
const BYTE *m_BufferPosBefore;
const Byte *m_BufferPosBefore;
};
STDMETHODIMP CMatchFinderCallback::BeforeChangingBufferPos()
@@ -33,11 +35,11 @@ STDMETHODIMP CMatchFinderCallback::AfterChangingBufferPos()
return S_OK;
}
HRESULT CMatchFinderMT::SetMatchFinder(IMatchFinder *aMatchFinder,
UINT32 multiThreadMult)
HRESULT CMatchFinderMT::SetMatchFinder(IMatchFinder *matchFinder,
UInt32 multiThreadMult)
{
_multiThreadMult = multiThreadMult;
m_MatchFinder = aMatchFinder;
m_MatchFinder = matchFinder;
CMyComPtr<IMatchFinderSetCallback> matchFinderSetCallback;
if (m_MatchFinder.QueryInterface(IID_IMatchFinderSetCallback,
&matchFinderSetCallback) == S_OK)
@@ -54,69 +56,63 @@ HRESULT CMatchFinderMT::SetMatchFinder(IMatchFinder *aMatchFinder,
}
STDMETHODIMP CMatchFinderMT::Init(ISequentialInStream *aStream)
STDMETHODIMP CMatchFinderMT::Init(ISequentialInStream *s)
{
// OutputDebugString("Init\n");
m_AskChangeBufferPos.Reset();
m_CanChangeBufferPos.Reset();
m_BufferPosWasChanged.Reset();
m_StopWriting.Reset();
m_WritingWasStopped.Reset();
m_NeedStart = true;
HRESULT aResult = m_MatchFinder->Init(aStream);
if (aResult == S_OK)
m_CurrentPos = 0;
m_CurrentLimitPos = 0;
HRESULT result = m_MatchFinder->Init(s);
if (result == S_OK)
m_DataCurrentPos = m_MatchFinder->GetPointerToCurrentPos();
return aResult;
return result;
}
STDMETHODIMP_(void) CMatchFinderMT::ReleaseStream()
{
// OutputDebugString("ReleaseStream\n");
m_StopWriting.Set();
m_WritingWasStopped.Lock();
// OutputDebugString("m_WritingWasStopped\n");
m_MatchFinder->ReleaseStream();
}
STDMETHODIMP CMatchFinderMT::MovePos()
{
if (m_Result != S_OK)
return m_Result;
m_NumAvailableBytesCurrent--;
m_DataCurrentPos++;
return S_OK;
}
STDMETHODIMP_(BYTE) CMatchFinderMT::GetIndexByte(UINT32 anIndex)
STDMETHODIMP_(Byte) CMatchFinderMT::GetIndexByte(Int32 index)
{
return m_DataCurrentPos[anIndex];
return m_DataCurrentPos[index];
}
STDMETHODIMP_(UINT32) CMatchFinderMT::GetMatchLen(UINT32 aIndex,
UINT32 aBack, UINT32 aLimit)
STDMETHODIMP_(UInt32) CMatchFinderMT::GetMatchLen(Int32 index,
UInt32 distance, UInt32 limit)
{
if (int(aIndex + aLimit) > m_NumAvailableBytesCurrent)
aLimit = m_NumAvailableBytesCurrent - (aIndex);
aBack++;
const BYTE *pby = m_DataCurrentPos + aIndex;
UINT32 i;
for(i = 0; i < aLimit && pby[i] == pby[i - aBack]; i++);
/*
char aSz[100];
sprintf(aSz, "GetMatchLen = %d", i);
OutputDebugString(aSz);
OutputDebugString("\n");
*/
if (int(index + limit) > m_NumAvailableBytesCurrent)
limit = m_NumAvailableBytesCurrent - (index);
distance++;
const Byte *pby = m_DataCurrentPos + index;
UInt32 i;
for(i = 0; i < limit && pby[i] == pby[i - distance]; i++);
return i;
// return m_MatchFinder->GetMatchLen(aIndex, aBack, aLimit); }
}
STDMETHODIMP_(const BYTE *) CMatchFinderMT::GetPointerToCurrentPos()
STDMETHODIMP_(const Byte *) CMatchFinderMT::GetPointerToCurrentPos()
{
return m_DataCurrentPos;
}
STDMETHODIMP_(UINT32) CMatchFinderMT::GetNumAvailableBytes()
STDMETHODIMP_(UInt32) CMatchFinderMT::GetNumAvailableBytes()
{
if (m_NeedStart)
return m_MatchFinder->GetNumAvailableBytes();
@@ -126,93 +122,110 @@ STDMETHODIMP_(UINT32) CMatchFinderMT::GetNumAvailableBytes()
void CMatchFinderMT::FreeMem()
{
delete []m_Buffer;
MyFree(m_Buffer);
MyFree(m_DummyBuffer);
}
STDMETHODIMP CMatchFinderMT::Create(UINT32 aSizeHistory,
UINT32 aKeepAddBufferBefore, UINT32 matchMaxLen,
UINT32 aKeepAddBufferAfter)
STDMETHODIMP CMatchFinderMT::Create(UInt32 sizeHistory,
UInt32 keepAddBufferBefore, UInt32 matchMaxLen,
UInt32 keepAddBufferAfter)
{
FreeMem();
m_MatchMaxLen = matchMaxLen;
m_BlockSize = (matchMaxLen + 1) * _multiThreadMult;
UINT32 aBufferSize = m_BlockSize * kNumMTBlocks;
m_Buffer = new UINT32[aBufferSize];
UInt32 bufferSize = m_BlockSize * kNumMTBlocks;
m_DummyBuffer = (UInt32 *)MyAlloc((matchMaxLen + 1) * sizeof(UInt32));
if (m_DummyBuffer == 0)
return E_OUTOFMEMORY;
m_Buffer = (UInt32 *)MyAlloc(bufferSize * sizeof(UInt32));
if (m_Buffer == 0)
return E_OUTOFMEMORY;
for (int i = 0; i < kNumMTBlocks; i++)
m_Buffers[i] = &m_Buffer[i * m_BlockSize];
m_NeedStart = true;
m_CurrentPos = 0;
m_CurrentLimitPos = 0;
aKeepAddBufferBefore += aBufferSize;
keepAddBufferBefore += bufferSize;
return m_MatchFinder->Create(aSizeHistory,
aKeepAddBufferBefore, matchMaxLen,
aKeepAddBufferAfter);
return m_MatchFinder->Create(sizeHistory, keepAddBufferBefore, matchMaxLen,
keepAddBufferAfter);
}
static DWORD WINAPI MFThread(void *aThreadCoderInfo)
static DWORD WINAPI MFThread(void *threadCoderInfo)
{
CMatchFinderMT &aMT = *(CMatchFinderMT *)aThreadCoderInfo;
CMatchFinderMT &mt = *(CMatchFinderMT *)threadCoderInfo;
return mt.ThreadFunc();
}
DWORD CMatchFinderMT::ThreadFunc()
{
bool errorMode = false;
while (true)
{
HANDLE anEvents[3] = { aMT.m_ExitEvent, aMT.m_StopWriting, aMT.m_CanWriteEvents[aMT.m_WriteBufferIndex] } ;
DWORD anWaitResult = ::WaitForMultipleObjects(3, anEvents, FALSE, INFINITE);
if (anWaitResult == WAIT_OBJECT_0 + 0)
HANDLE events[3] = { m_ExitEvent, m_StopWriting, m_CanWriteEvents[m_WriteBufferIndex] } ;
DWORD waitResult = ::WaitForMultipleObjects((errorMode ? 2: 3), events, FALSE, INFINITE);
if (waitResult == WAIT_OBJECT_0 + 0)
return 0;
if (anWaitResult == WAIT_OBJECT_0 + 1)
if (waitResult == WAIT_OBJECT_0 + 1)
{
// OutputDebugString("m_StopWriting\n");
aMT.m_WriteBufferIndex = 0;
m_WriteBufferIndex = 0;
for (int i = 0; i < kNumMTBlocks; i++)
aMT.m_CanWriteEvents[i].Reset();
aMT.m_WritingWasStopped.Set();
m_CanWriteEvents[i].Reset();
m_WritingWasStopped.Set();
errorMode = false;
continue;
}
// OutputDebugString("m_CanWriteEvents\n");
UINT32 *aBuffer = aMT.m_Buffers[aMT.m_WriteBufferIndex];
UINT32 aCurPos = 0;
UINT32 aNumBytes = 0;
while (aCurPos + aMT.m_MatchMaxLen + 1 <= aMT.m_BlockSize)
if (errorMode)
{
if (aMT.m_MatchFinder->GetNumAvailableBytes() == 0)
break;
UINT32 aLen = aMT.m_MatchFinder->GetLongestMatch(aBuffer + aCurPos);
/*
if (aLen == 1)
aLen = 0;
*/
aBuffer[aCurPos] = aLen;
aCurPos += aLen + 1;
HRESULT aResult = aMT.m_MatchFinder->MovePos();
if (aResult != S_OK)
throw 124459;
aNumBytes++;
// this case means bug_in_program. So just exit;
return 1;
}
aMT.m_LimitPos[aMT.m_WriteBufferIndex] = aCurPos;
aMT.m_NumAvailableBytes[aMT.m_WriteBufferIndex] =
aNumBytes + aMT.m_MatchFinder->GetNumAvailableBytes();
// char aSz[100];
// sprintf(aSz, "x = %d", aMT.m_WriteBufferIndex);
// OutputDebugString(aSz);
// OutputDebugString("aMT.m_CanReadEvents\n");
aMT.m_CanReadEvents[aMT.m_WriteBufferIndex].Set();
aMT.m_WriteBufferIndex++;
if (aMT.m_WriteBufferIndex == kNumMTBlocks)
aMT.m_WriteBufferIndex = 0;
}
/*
while(true)
{
if (!((CCoderMixer2 *)aThreadCoderInfo)->MyCode())
return 0;
m_Results[m_WriteBufferIndex] = S_OK;
UInt32 *buffer = m_Buffers[m_WriteBufferIndex];
UInt32 curPos = 0;
UInt32 numBytes = 0;
UInt32 limit = m_BlockSize - m_MatchMaxLen;
IMatchFinder *mf = m_MatchFinder;
do
{
if (mf->GetNumAvailableBytes() == 0)
break;
UInt32 len = mf->GetLongestMatch(buffer + curPos);
/*
if (len == 1)
len = 0;
*/
buffer[curPos] = len;
curPos += len + 1;
numBytes++;
HRESULT result = mf->MovePos();
if (result != S_OK)
{
m_Results[m_WriteBufferIndex] = result;
errorMode = true;
break;
}
}
while (curPos < limit);
m_LimitPos[m_WriteBufferIndex] = curPos;
if (errorMode)
m_NumAvailableBytes[m_WriteBufferIndex] = numBytes;
else
m_NumAvailableBytes[m_WriteBufferIndex] = numBytes +
mf->GetNumAvailableBytes();
m_CanReadEvents[m_WriteBufferIndex].Set();
if (++m_WriteBufferIndex == kNumMTBlocks)
m_WriteBufferIndex = 0;
}
*/
}
CMatchFinderMT::CMatchFinderMT():
m_Buffer(0),
m_DummyBuffer(0),
_multiThreadMult(100)
{
for (int i = 0; i < kNumMTBlocks; i++)
@@ -227,17 +240,16 @@ CMatchFinderMT::CMatchFinderMT():
if (!m_Thread.Create(MFThread, this))
throw 271826;
}
CMatchFinderMT::~CMatchFinderMT()
{
m_ExitEvent.Set();
if (HANDLE(m_Thread) != 0)
::WaitForSingleObject(m_Thread, INFINITE);
m_Thread.Wait();
FreeMem();
}
void CMatchFinderMT::Start()
{
// OutputDebugString("Start\n");
m_AskChangeBufferPos.Reset();
m_CanChangeBufferPos.Reset();
m_BufferPosWasChanged.Reset();
@@ -247,6 +259,7 @@ void CMatchFinderMT::Start()
m_NeedStart = false;
m_CurrentPos = 0;
m_CurrentLimitPos = 0;
m_Result = S_OK;
int i;
for (i = 0; i < kNumMTBlocks; i++)
m_CanReadEvents[i].Reset();
@@ -254,29 +267,17 @@ void CMatchFinderMT::Start()
m_CanWriteEvents[i].Set();
}
STDMETHODIMP_(UINT32) CMatchFinderMT::GetLongestMatch(UINT32 *aDistances)
STDMETHODIMP_(UInt32) CMatchFinderMT::GetLongestMatch(UInt32 *distances)
{
// OutputDebugString("GetLongestMatch\n");
if (m_NeedStart)
Start();
/*
if (m_CurrentPos > m_CurrentLimitPos)
throw 1123324;
*/
if (m_CurrentPos == m_CurrentLimitPos)
{
// OutputDebugString("m_CurrentPos == m_CurrentLimitPos\n");
if (m_NeedStart)
Start();
while (true)
{
/*
char aSz[100];
sprintf(aSz, "m_CanReadEvents[m_ReadBufferIndex] = %d\n", m_ReadBufferIndex);
OutputDebugString(aSz);
OutputDebugString("\n");
*/
HANDLE anEvents[2] = { m_AskChangeBufferPos, m_CanReadEvents[m_ReadBufferIndex] } ;
DWORD anWaitResult = ::WaitForMultipleObjects(2, anEvents, FALSE, INFINITE);
if (anWaitResult == WAIT_OBJECT_0 + 1)
HANDLE events[2] = { m_AskChangeBufferPos, m_CanReadEvents[m_ReadBufferIndex] } ;
DWORD waitResult = ::WaitForMultipleObjects(2, events, FALSE, INFINITE);
if (waitResult == WAIT_OBJECT_0 + 1)
break;
m_BufferPosWasChanged.Reset();
m_CanChangeBufferPos.Set();
@@ -286,32 +287,26 @@ STDMETHODIMP_(UINT32) CMatchFinderMT::GetLongestMatch(UINT32 *aDistances)
m_CurrentLimitPos = m_LimitPos[m_ReadBufferIndex];
m_NumAvailableBytesCurrent = m_NumAvailableBytes[m_ReadBufferIndex];
m_CurrentPos = 0;
m_Result = m_Results[m_ReadBufferIndex];
}
/*
if (m_CurrentPos >= m_CurrentLimitPos)
throw 1123324;
const UINT32 *aBuffer = m_Buffers[m_ReadBufferIndex];
UINT32 aLen = aBuffer[m_CurrentPos++];
for (UINT32 i = 1; i <= aLen; i++)
aDistances[i] = aBuffer[m_CurrentPos++];
*/
const UInt32 *buffer = m_Buffers[m_ReadBufferIndex];
UInt32 len = buffer[m_CurrentPos++];
for (UInt32 i = 1; i <= len; i++)
distances[i] = buffer[m_CurrentPos++];
if (m_CurrentPos == m_CurrentLimitPos)
{
m_CanWriteEvents[m_ReadBufferIndex].Set();
m_ReadBufferIndex++;
if (m_ReadBufferIndex == kNumMTBlocks)
if (++m_ReadBufferIndex == kNumMTBlocks)
m_ReadBufferIndex = 0;
}
// char aSz[100];
// sprintf(aSz, "m_NumAvailableBytesCurrent = %d", m_NumAvailableBytesCurrent);
// OutputDebugString(aSz);
// OutputDebugString("\n");
return aLen;
return len;
}
STDMETHODIMP_(void) CMatchFinderMT::DummyLongestMatch()
{
UINT32 aBuffer[512];
GetLongestMatch(aBuffer);
// m_MatchFinder->DummyLongestMatch();
GetLongestMatch(m_DummyBuffer);
}

View File

@@ -1,14 +1,12 @@
// MT_MF.h
// LZ/MT.h
#pragma once
#ifndef __LZ_MT_H
#define __LZ_MT_H
#ifndef __MT_MF_H
#define __MT_MF_H
#include "../../../../Common/MyCom.h"
#include "Common/MyCom.h"
#include "Windows/Thread.h"
#include "Windows/Synchronization.h"
#include "../../../../Windows/Thread.h"
#include "../../../../Windows/Synchronization.h"
#include "../../../ICoder.h"
#include "../IMatchFinder.h"
@@ -21,65 +19,65 @@ class CMatchFinderMT:
{
MY_UNKNOWN_IMP
STDMETHOD(Init)(ISequentialInStream *aStream);
STDMETHOD(Init)(ISequentialInStream *s);
STDMETHOD_(void, ReleaseStream)();
STDMETHOD(MovePos)();
STDMETHOD_(BYTE, GetIndexByte)(UINT32 anIndex);
STDMETHOD_(UINT32, GetMatchLen)(UINT32 aIndex, UINT32 aBack, UINT32 aLimit);
STDMETHOD_(UINT32, GetNumAvailableBytes)();
STDMETHOD_(const BYTE *, GetPointerToCurrentPos)();
STDMETHOD(Create)(UINT32 aSizeHistory,
UINT32 aKeepAddBufferBefore, UINT32 aMatchMaxLen,
UINT32 aKeepAddBufferAfter);
STDMETHOD_(UINT32, GetLongestMatch)(UINT32 *aDistances);
STDMETHOD_(Byte, GetIndexByte)(Int32 index);
STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit);
STDMETHOD_(UInt32, GetNumAvailableBytes)();
STDMETHOD_(const Byte *, GetPointerToCurrentPos)();
STDMETHOD(Create)(UInt32 sizeHistory,
UInt32 keepAddBufferBefore, UInt32 matchMaxLen,
UInt32 keepAddBufferAfter);
STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);
STDMETHOD_(void, DummyLongestMatch)();
private:
public:
CMyComPtr<IMatchFinder> m_MatchFinder;
UINT32 m_MatchMaxLen;
UInt32 m_CurrentPos;
UInt32 m_CurrentLimitPos;
UInt32 m_MatchMaxLen;
UINT32 m_BlockSize;
// UINT32 m_BufferSize;
UINT32 *m_Buffer;
UINT32 *m_Buffers[kNumMTBlocks];
UInt32 m_BlockSize;
UInt32 *m_Buffer;
UInt32 *m_Buffers[kNumMTBlocks];
UInt32 *m_DummyBuffer;
bool m_NeedStart;
UINT32 m_WriteBufferIndex;
UINT32 m_ReadBufferIndex;
UInt32 m_WriteBufferIndex;
UInt32 m_ReadBufferIndex;
NWindows::NSynchronization::CAutoResetEvent m_StopWriting;
NWindows::NSynchronization::CAutoResetEvent m_WritingWasStopped;
NWindows::NSynchronization::CManualResetEvent m_ExitEvent;
NWindows::NSynchronization::CAutoResetEvent m_CanReadEvents[kNumMTBlocks];
NWindows::NSynchronization::CAutoResetEvent m_CanWriteEvents[kNumMTBlocks];
HRESULT m_Results[kNumMTBlocks];
UInt32 m_LimitPos[kNumMTBlocks];
UInt32 m_NumAvailableBytes[kNumMTBlocks];
UInt32 m_NumAvailableBytesCurrent;
NWindows::CThread m_Thread;
UInt32 _multiThreadMult;
HRESULT m_Result;
void Start();
void FreeMem();
public:
NWindows::NSynchronization::CAutoResetEvent m_AskChangeBufferPos;
NWindows::NSynchronization::CAutoResetEvent m_CanChangeBufferPos;
NWindows::NSynchronization::CAutoResetEvent m_BufferPosWasChanged;
CMyComPtr<IMatchFinder> m_MatchFinder;
const Byte *m_DataCurrentPos;
NWindows::NSynchronization::CManualResetEvent m_ExitEvent;
// NWindows::NSynchronization::CManualResetEvent m_NewStart;
NWindows::NSynchronization::CAutoResetEvent m_CanReadEvents[kNumMTBlocks];
NWindows::NSynchronization::CAutoResetEvent m_CanWriteEvents[kNumMTBlocks];
UINT32 m_LimitPos[kNumMTBlocks];
UINT32 m_NumAvailableBytes[kNumMTBlocks];
UINT32 m_NumAvailableBytesCurrent;
const BYTE *m_DataCurrentPos;
DWORD ThreadFunc();
UINT32 m_CurrentLimitPos;
UINT32 m_CurrentPos;
NWindows::CThread m_Thread;
// bool m_WriteWasClosed;
UINT32 _multiThreadMult;
public:
CMatchFinderMT();
~CMatchFinderMT();
void Start();
void FreeMem();
HRESULT SetMatchFinder(IMatchFinder *aMatchFinder,
UINT32 multiThreadMult = 200);
HRESULT SetMatchFinder(IMatchFinder *matchFinder, UInt32 multiThreadMult = 200);
};
#endif

View File

@@ -1,8 +1,8 @@
// stdafx.h
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include <windows.h>
#include "../../../../Common/MyWindows.h"
#endif
#endif

View File

@@ -1,12 +1,10 @@
// Pat.h
// #pragma once
// #ifndef __PATRICIA__H
// #define __PATRICIA__H
#include "../../../../Common/AlignedBuffer.h"
#include "../../../../Common/MyCom.h"
#include "../../../../Common/Types.h"
#include "../LZInWindow.h"
namespace PAT_NAMESPACE {
@@ -15,13 +13,8 @@ struct CNode;
typedef CNode *CNodePointer;
#pragma pack(push, PragmaPatrTree)
#pragma pack(push, 1)
// #define __AUTO_REMOVE
// #define __USE_3_BYTES
// #define __NODE_4_BITS
// #define __NODE_3_BITS
// #define __NODE_2_BITS
@@ -30,55 +23,32 @@ typedef CNode *CNodePointer;
// #define __HASH_3
#ifdef __USE_3_BYTES
struct CIndex
{
BYTE Data[3];
operator =(UINT32 aValue)
{
Data[0] = aValue & 0xFF;
Data[1] = (aValue >> 8) & 0xFF;
Data[2] = (aValue >> 16) & 0xFF;
}
operator UINT32() const { return (*((const UINT32 *)Data)) & 0xFFFFFF; }
};
#else
typedef UINT32 CIndex;
#endif
#pragma pack(pop)
#pragma pack(pop, PragmaPatrTree)
typedef UInt32 CIndex;
#ifdef __NODE_4_BITS
typedef UINT32 CIndex2;
typedef UINT32 CSameBitsType;
typedef UInt32 CIndex2;
typedef UInt32 CSameBitsType;
#else
#ifdef __NODE_3_BITS
typedef UINT32 CIndex2;
typedef UINT32 CSameBitsType;
typedef UInt32 CIndex2;
typedef UInt32 CSameBitsType;
#else
#ifdef __USE_3_BYTES
typedef BYTE CSameBitsType;
#else
typedef UINT32 CIndex;
typedef UINT32 CSameBitsType;
#endif
typedef UInt32 CIndex;
typedef UInt32 CSameBitsType;
typedef CIndex CIndex2;
#endif
#endif
const UINT32 kNumBitsInIndex = sizeof(CIndex) * 8;
const UINT32 kMatchStartValue = UINT32(1) << (kNumBitsInIndex - 1);
const UInt32 kNumBitsInIndex = sizeof(CIndex) * 8;
const UInt32 kMatchStartValue = UInt32(1) << (kNumBitsInIndex - 1);
// don't change kMatchStartValue definition, since it is used in
// PatMain.h:
typedef CIndex CMatchPointer;
const UINT32 kDescendantEmptyValue = kMatchStartValue - 1;
#pragma pack(push, PragmaPatrTree2)
#pragma pack(push, 1)
const UInt32 kDescendantEmptyValue = kMatchStartValue - 1;
union CDescendant
{
@@ -90,33 +60,27 @@ union CDescendant
void MakeEmpty() { NodePointer = kDescendantEmptyValue; }
};
#pragma pack(pop)
#pragma pack(pop, PragmaPatrTree2)
#pragma pack( push, PragmaBackNode)
#pragma pack( push, 1)
#undef MY_BYTE_SIZE
#ifdef __NODE_4_BITS
#define MY_BYTE_SIZE 8
const UINT32 kNumSubBits = 4;
const UInt32 kNumSubBits = 4;
#else
#ifdef __NODE_3_BITS
#define MY_BYTE_SIZE 9
const UINT32 kNumSubBits = 3;
const UInt32 kNumSubBits = 3;
#else
#define MY_BYTE_SIZE 8
#ifdef __NODE_2_BITS
const UINT32 kNumSubBits = 2;
const UInt32 kNumSubBits = 2;
#else
const UINT32 kNumSubBits = 1;
const UInt32 kNumSubBits = 1;
#endif
#endif
#endif
const UINT32 kNumSubNodes = 1 << kNumSubBits;
const UINT32 kSubNodesMask = kNumSubNodes - 1;
const UInt32 kNumSubNodes = 1 << kNumSubBits;
const UInt32 kSubNodesMask = kNumSubNodes - 1;
struct CNode
{
@@ -125,18 +89,15 @@ struct CNode
union
{
CDescendant Descendants[kNumSubNodes];
UINT32 NextFreeNode;
UInt32 NextFreeNode;
};
#ifdef __NODE_2_BITS
#ifdef __NODE_2_BITS_PADDING
UINT32 Padding[2];
UInt32 Padding[2];
#endif
#endif
};
#pragma pack(pop)
#pragma pack(pop, PragmaBackNode)
#undef kIDNumBitsByte
#undef kIDNumBitsString
@@ -183,13 +144,8 @@ struct CNode
#undef kIDUse3BytesByte
#undef kIDUse3BytesString
#ifdef __USE_3_BYTES
#define kIDUse3BytesByte 0x02
#define kIDUse3BytesString TEXT("T")
#else
#define kIDUse3BytesByte 0x00
#define kIDUse3BytesString TEXT("")
#endif
#define kIDUse3BytesByte 0x00
#define kIDUse3BytesString TEXT("")
#undef kIDPaddingByte
#undef kIDPaddingString
@@ -227,23 +183,23 @@ class CPatricia:
STDMETHOD(Init)(ISequentialInStream *aStream);
STDMETHOD_(void, ReleaseStream)();
STDMETHOD(MovePos)();
STDMETHOD_(BYTE, GetIndexByte)(UINT32 anIndex);
STDMETHOD_(UINT32, GetMatchLen)(UINT32 aIndex, UINT32 aBack, UINT32 aLimit);
STDMETHOD_(UINT32, GetNumAvailableBytes)();
STDMETHOD(Create)(UINT32 aSizeHistory,
UINT32 aKeepAddBufferBefore, UINT32 aMatchMaxLen,
UINT32 aKeepAddBufferAfter);
STDMETHOD_(UINT32, GetLongestMatch)(UINT32 *aDistances);
STDMETHOD_(Byte, GetIndexByte)(Int32 index);
STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);
STDMETHOD_(UInt32, GetNumAvailableBytes)();
STDMETHOD(Create)(UInt32 historySize,
UInt32 keepAddBufferBefore, UInt32 matchMaxLen,
UInt32 keepAddBufferAfter);
STDMETHOD_(UInt32, GetLongestMatch)(UInt32 *distances);
STDMETHOD_(void, DummyLongestMatch)();
STDMETHOD_(const BYTE *, GetPointerToCurrentPos)();
STDMETHOD_(const Byte *, GetPointerToCurrentPos)();
void FreeMemory();
public:
CPatricia();
~CPatricia();
UINT32 _sizeHistory;
UINT32 _matchMaxLen;
UInt32 _sizeHistory;
UInt32 _matchMaxLen;
CDescendant *m_HashDescendants;
#ifdef __HASH_3
@@ -252,21 +208,19 @@ public:
CNode *m_Nodes;
UINT32 m_FreeNode;
UINT32 m_FreeNodeMax;
UInt32 m_FreeNode;
UInt32 m_FreeNodeMax;
#ifdef __AUTO_REMOVE
UINT32 m_NumUsedNodes;
UINT32 m_NumNodes;
UInt32 m_NumUsedNodes;
UInt32 m_NumNodes;
#else
bool m_SpecialRemoveMode;
#endif
bool m_SpecialMode;
UINT32 m_NumNotChangedCycles;
UINT32 *m_TmpBacks;
CAlignedBuffer m_AlignBuffer;
UInt32 m_NumNotChangedCycles;
UInt32 *m_TmpBacks;
CMyComPtr<IMatchFinderCallback> m_Callback;
@@ -274,25 +228,25 @@ public:
virtual void AfterMoveBlock();
// IMatchFinderSetCallback
STDMETHOD(SetCallback)(IMatchFinderCallback *aCallback);
STDMETHOD(SetCallback)(IMatchFinderCallback *callback);
void ChangeLastMatch(UINT32 aHashValue);
void ChangeLastMatch(UInt32 hashValue);
#ifdef __AUTO_REMOVE
void TestRemoveDescendant(CDescendant &aDescendant, UINT32 aLimitPos);
void TestRemoveDescendant(CDescendant &descendant, UInt32 limitPos);
void TestRemoveNodes();
void RemoveNode(UINT32 anIndex);
void TestRemoveAndNormalizeDescendant(CDescendant &aDescendant,
UINT32 aLimitPos, UINT32 aSubValue);
void RemoveNode(UInt32 index);
void TestRemoveAndNormalizeDescendant(CDescendant &descendant,
UInt32 limitPos, UInt32 subValue);
void TestRemoveNodesAndNormalize();
#else
void NormalizeDescendant(CDescendant &aDescendant, UINT32 aSubValue);
void NormalizeDescendant(CDescendant &descendant, UInt32 subValue);
void Normalize();
void RemoveMatch();
#endif
private:
void AddInternalNode(CNodePointer aNode, CIndex *aNodePointerPointer,
BYTE aByte, BYTE aByteXOR, UINT32 aNumSameBits, UINT32 aPos)
Byte aByte, Byte aByteXOR, UInt32 aNumSameBits, UInt32 aPos)
{
while((aByteXOR & kSubNodesMask) == 0)
{
@@ -302,7 +256,7 @@ private:
}
// Insert New Node
CNodePointer aNewNode = &m_Nodes[m_FreeNode];
UINT32 aNodeIndex = *aNodePointerPointer;
UInt32 aNodeIndex = *aNodePointerPointer;
*aNodePointerPointer = m_FreeNode;
m_FreeNode = aNewNode->NextFreeNode;
#ifdef __AUTO_REMOVE
@@ -314,9 +268,9 @@ private:
m_Nodes[m_FreeNode].NextFreeNode = m_FreeNode + 1;
}
UINT32 aBitsNew = aByte & kSubNodesMask;
UINT32 aBitsOld = (aByte ^ aByteXOR) & kSubNodesMask;
for (UINT32 i = 0; i < kNumSubNodes; i++)
UInt32 aBitsNew = aByte & kSubNodesMask;
UInt32 aBitsOld = (aByte ^ aByteXOR) & kSubNodesMask;
for (UInt32 i = 0; i < kNumSubNodes; i++)
aNewNode->Descendants[i].NodePointer = kDescendantEmptyValue;
aNewNode->Descendants[aBitsNew].MatchPointer = aPos + kMatchStartValue;
aNewNode->Descendants[aBitsOld].NodePointer = aNodeIndex;
@@ -326,15 +280,15 @@ private:
aNode->NumSameBits = CSameBitsType(aNumSameBits - kNumSubBits);
}
void AddLeafNode(CNodePointer aNode, BYTE aByte, BYTE aByteXOR,
UINT32 aNumSameBits, UINT32 aPos, UINT32 aDescendantIndex)
void AddLeafNode(CNodePointer aNode, Byte aByte, Byte aByteXOR,
UInt32 aNumSameBits, UInt32 aPos, UInt32 aDescendantIndex)
{
for(;(aByteXOR & kSubNodesMask) == 0; aNumSameBits += kNumSubBits)
{
aByte >>= kNumSubBits;
aByteXOR >>= kNumSubBits;
}
UINT32 aNewNodeIndex = m_FreeNode;
UInt32 aNewNodeIndex = m_FreeNode;
CNodePointer aNewNode = &m_Nodes[m_FreeNode];
m_FreeNode = aNewNode->NextFreeNode;
#ifdef __AUTO_REMOVE
@@ -346,9 +300,9 @@ private:
m_Nodes[m_FreeNode].NextFreeNode = m_FreeNode + 1;
}
UINT32 aBitsNew = (aByte & kSubNodesMask);
UINT32 aBitsOld = (aByte ^ aByteXOR) & kSubNodesMask;
for (UINT32 i = 0; i < kNumSubNodes; i++)
UInt32 aBitsNew = (aByte & kSubNodesMask);
UInt32 aBitsOld = (aByte ^ aByteXOR) & kSubNodesMask;
for (UInt32 i = 0; i < kNumSubNodes; i++)
aNewNode->Descendants[i].NodePointer = kDescendantEmptyValue;
aNewNode->Descendants[aBitsNew].MatchPointer = aPos + kMatchStartValue;
aNewNode->Descendants[aBitsOld].MatchPointer =

View File

@@ -1,7 +1,5 @@
// Pat2.h
#pragma once
#ifndef __PAT2__H
#define __PAT2__H

View File

@@ -1,7 +1,5 @@
// Pat2H.h
#pragma once
#ifndef __PAT2H__H
#define __PAT2H__H

View File

@@ -1,7 +1,5 @@
// Pat2R.h
#pragma once
#ifndef __PAT2R__H
#define __PAT2R__H

View File

@@ -1,7 +1,5 @@
// Pat3H.h
#pragma once
#ifndef __PAT3H__H
#define __PAT3H__H

View File

@@ -1,7 +1,5 @@
// Pat4H.h
#pragma once
#ifndef __PAT4H__H
#define __PAT4H__H

View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,8 +1,6 @@
// stdafx.h
// StdAfx.h
#ifndef __STDAFX_H
#define __STDAFX_H
#include <windows.h>
#endif