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