rlm@1: /* LzFind.h -- Match finder for LZ algorithms rlm@1: 2008-10-04 : Igor Pavlov : Public domain */ rlm@1: rlm@1: #ifndef __LZFIND_H rlm@1: #define __LZFIND_H rlm@1: rlm@1: #include "Types.h" rlm@1: rlm@1: typedef UInt32 CLzRef; rlm@1: rlm@1: typedef struct _CMatchFinder rlm@1: { rlm@1: Byte *buffer; rlm@1: UInt32 pos; rlm@1: UInt32 posLimit; rlm@1: UInt32 streamPos; rlm@1: UInt32 lenLimit; rlm@1: rlm@1: UInt32 cyclicBufferPos; rlm@1: UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */ rlm@1: rlm@1: UInt32 matchMaxLen; rlm@1: CLzRef *hash; rlm@1: CLzRef *son; rlm@1: UInt32 hashMask; rlm@1: UInt32 cutValue; rlm@1: rlm@1: Byte *bufferBase; rlm@1: ISeqInStream *stream; rlm@1: int streamEndWasReached; rlm@1: rlm@1: UInt32 blockSize; rlm@1: UInt32 keepSizeBefore; rlm@1: UInt32 keepSizeAfter; rlm@1: rlm@1: UInt32 numHashBytes; rlm@1: int directInput; rlm@1: int btMode; rlm@1: /* int skipModeBits; */ rlm@1: int bigHash; rlm@1: UInt32 historySize; rlm@1: UInt32 fixedHashSize; rlm@1: UInt32 hashSizeSum; rlm@1: UInt32 numSons; rlm@1: SRes result; rlm@1: UInt32 crc[256]; rlm@1: } CMatchFinder; rlm@1: rlm@1: #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer) rlm@1: #define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)]) rlm@1: rlm@1: #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos) rlm@1: rlm@1: int MatchFinder_NeedMove(CMatchFinder *p); rlm@1: Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p); rlm@1: void MatchFinder_MoveBlock(CMatchFinder *p); rlm@1: void MatchFinder_ReadIfRequired(CMatchFinder *p); rlm@1: rlm@1: void MatchFinder_Construct(CMatchFinder *p); rlm@1: rlm@1: /* Conditions: rlm@1: historySize <= 3 GB rlm@1: keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB rlm@1: */ rlm@1: int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, rlm@1: UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, rlm@1: ISzAlloc *alloc); rlm@1: void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc); rlm@1: void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems); rlm@1: void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue); rlm@1: rlm@1: UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son, rlm@1: UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, rlm@1: UInt32 *distances, UInt32 maxLen); rlm@1: rlm@1: /* rlm@1: Conditions: rlm@1: Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func. rlm@1: Mf_GetPointerToCurrentPos_Func's result must be used only before any other function rlm@1: */ rlm@1: rlm@1: typedef void (*Mf_Init_Func)(void *object); rlm@1: typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index); rlm@1: typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object); rlm@1: typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object); rlm@1: typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances); rlm@1: typedef void (*Mf_Skip_Func)(void *object, UInt32); rlm@1: rlm@1: typedef struct _IMatchFinder rlm@1: { rlm@1: Mf_Init_Func Init; rlm@1: Mf_GetIndexByte_Func GetIndexByte; rlm@1: Mf_GetNumAvailableBytes_Func GetNumAvailableBytes; rlm@1: Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos; rlm@1: Mf_GetMatches_Func GetMatches; rlm@1: Mf_Skip_Func Skip; rlm@1: } IMatchFinder; rlm@1: rlm@1: void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable); rlm@1: rlm@1: void MatchFinder_Init(CMatchFinder *p); rlm@1: UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); rlm@1: UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); rlm@1: void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); rlm@1: void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); rlm@1: rlm@1: #endif