1/* MatchFinder.h */ 2 3#ifndef __MATCHFINDER_H 4#define __MATCHFINDER_H 5 6#include "../../IStream.h" 7 8typedef UInt32 CLzRef; 9 10typedef struct _CMatchFinder 11{ 12 Byte *buffer; 13 UInt32 pos; 14 UInt32 posLimit; 15 UInt32 streamPos; 16 UInt32 lenLimit; 17 18 UInt32 cyclicBufferPos; 19 UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */ 20 21 UInt32 matchMaxLen; 22 CLzRef *hash; 23 CLzRef *son; 24 UInt32 hashMask; 25 UInt32 cutValue; 26 27 Byte *bufferBase; 28 ISeqInStream *stream; 29 int streamEndWasReached; 30 31 UInt32 blockSize; 32 UInt32 keepSizeBefore; 33 UInt32 keepSizeAfter; 34 35 UInt32 numHashBytes; 36 int directInput; 37 int btMode; 38 /* int skipModeBits; */ 39 int bigHash; 40 UInt32 historySize; 41 UInt32 fixedHashSize; 42 UInt32 hashSizeSum; 43 UInt32 numSons; 44 45 HRes result; 46} CMatchFinder; 47 48#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer) 49#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)]) 50 51#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos) 52 53int MatchFinder_NeedMove(CMatchFinder *p); 54Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p); 55void MatchFinder_MoveBlock(CMatchFinder *p); 56void MatchFinder_ReadIfRequired(CMatchFinder *p); 57 58void MatchFinder_Construct(CMatchFinder *p); 59 60/* Conditions: 61 historySize <= 3 GB 62 keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB 63*/ 64int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, 65 UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, 66 ISzAlloc *alloc); 67void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc); 68void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems); 69void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue); 70 71UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son, 72 UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, 73 UInt32 *distances, UInt32 maxLen); 74 75/* 76Conditions: 77 Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func. 78 Mf_GetPointerToCurrentPos_Func's result must be used only before any other function 79*/ 80 81typedef void (*Mf_Init_Func)(void *object); 82typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index); 83typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object); 84typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object); 85typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances); 86typedef void (*Mf_Skip_Func)(void *object, UInt32); 87 88typedef struct _IMatchFinder 89{ 90 Mf_Init_Func Init; 91 Mf_GetIndexByte_Func GetIndexByte; 92 Mf_GetNumAvailableBytes_Func GetNumAvailableBytes; 93 Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos; 94 Mf_GetMatches_Func GetMatches; 95 Mf_Skip_Func Skip; 96} IMatchFinder; 97 98void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable); 99 100void MatchFinder_Init(CMatchFinder *p); 101UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); 102UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); 103void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); 104void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); 105 106#endif 107