1 /* LzFind.h -- Match finder for LZ algorithms
2 2024-01-22 : Igor Pavlov : Public domain */
4 #ifndef ZIP7_INC_LZ_FIND_H
5 #define ZIP7_INC_LZ_FIND_H
11 typedef UInt32 CLzRef;
18 UInt32 streamPos; /* wrap over Zero is allowed (streamPos < pos). Use (UInt32)(streamPos - pos) */
21 UInt32 cyclicBufferPos;
22 UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
24 Byte streamEndWasReached;
36 ISeqInStreamPtr stream;
39 UInt32 keepSizeBefore;
43 size_t directInputRem;
46 Byte numHashBytes_Min;
53 UInt64 expectedDataSize;
56 #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((const Byte *)(p)->buffer)
58 #define Inline_MatchFinder_GetNumAvailableBytes(p) ((UInt32)((p)->streamPos - (p)->pos))
61 #define Inline_MatchFinder_IsFinishedOK(p) \
62 ((p)->streamEndWasReached \
63 && (p)->streamPos == (p)->pos \
64 && (!(p)->directInput || (p)->directInputRem == 0))
67 int MatchFinder_NeedMove(CMatchFinder *p);
68 /* Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p); */
69 void MatchFinder_MoveBlock(CMatchFinder *p);
70 void MatchFinder_ReadIfRequired(CMatchFinder *p);
72 void MatchFinder_Construct(CMatchFinder *p);
74 /* (directInput = 0) is default value.
75 It's required to provide correct (directInput) value
76 before calling MatchFinder_Create().
77 You can set (directInput) by any of the following calls:
78 - MatchFinder_SET_DIRECT_INPUT_BUF()
79 - MatchFinder_SET_STREAM()
80 - MatchFinder_SET_STREAM_MODE()
83 #define MatchFinder_SET_DIRECT_INPUT_BUF(p, _src_, _srcLen_) { \
85 (p)->directInput = 1; \
86 (p)->buffer = (_src_); \
87 (p)->directInputRem = (_srcLen_); }
90 #define MatchFinder_SET_STREAM_MODE(p) { \
91 (p)->directInput = 0; }
94 #define MatchFinder_SET_STREAM(p, _stream_) { \
95 (p)->stream = _stream_; \
96 (p)->directInput = 0; }
99 int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
100 UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
102 void MatchFinder_Free(CMatchFinder *p, ISzAllocPtr alloc);
103 void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems);
106 #define MatchFinder_INIT_POS(p, val) \
108 (p)->streamPos = (val);
111 // void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
112 #define MatchFinder_REDUCE_OFFSETS(p, subValue) \
113 (p)->pos -= (subValue); \
114 (p)->streamPos -= (subValue);
117 UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
118 size_t _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
119 UInt32 *distances, UInt32 maxLen);
123 Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
124 Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
127 typedef void (*Mf_Init_Func)(void *object);
128 typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
129 typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
130 typedef UInt32 * (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
131 typedef void (*Mf_Skip_Func)(void *object, UInt32);
136 Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
137 Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
138 Mf_GetMatches_Func GetMatches;
142 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder2 *vTable);
144 void MatchFinder_Init_LowHash(CMatchFinder *p);
145 void MatchFinder_Init_HighHash(CMatchFinder *p);
146 void MatchFinder_Init_4(CMatchFinder *p);
147 // void MatchFinder_Init(CMatchFinder *p);
148 void MatchFinder_Init(void *p);
150 UInt32* Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
151 UInt32* Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
153 void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
154 void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
156 void LzFindPrepare(void);