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