1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
4 * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 **************************************************************************/
27 /* LzFind.h -- Match finder for LZ algorithms
28 2008-10-04 : Igor Pavlov : Public domain */
33 #include "lzma_Types.h"
38 typedef UInt32 CLzRef;
40 typedef struct _CMatchFinder
48 UInt32 cyclicBufferPos;
49 UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
59 int streamEndWasReached;
62 UInt32 keepSizeBefore;
68 /* int skipModeBits; */
78 #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
79 #define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])
81 #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
83 int MatchFinder_NeedMove(CMatchFinder *p);
84 Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
85 void MatchFinder_MoveBlock(CMatchFinder *p);
86 void MatchFinder_ReadIfRequired(CMatchFinder *p);
88 void MatchFinder_Construct(CMatchFinder *p);
92 keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
94 int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
95 UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
97 void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
98 void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
99 void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
101 UInt32 *GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
102 UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
103 UInt32 *distances, UInt32 maxLen);
107 Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
108 Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
111 typedef void (*Mf_Init_Func)(void *object);
112 typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);
113 typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
114 typedef const Byte *(*Mf_GetPointerToCurrentPos_Func)(void *object);
115 typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
116 typedef void (*Mf_Skip_Func)(void *object, UInt32);
118 typedef struct _IMatchFinder
121 Mf_GetIndexByte_Func GetIndexByte;
122 Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
123 Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
124 Mf_GetMatches_Func GetMatches;
128 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
130 void MatchFinder_Init(CMatchFinder *p);
131 UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
132 UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
133 void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
134 void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);