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