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