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