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