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