]> git.cworth.org Git - vogl/blob - src/voglcore/lzma_LzFind.h
Initial vogl checkin
[vogl] / src / voglcore / lzma_LzFind.h
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * Copyright 2010-2014 Rich Geldreich and Tenacious Software LLC
5  * All Rights Reserved.
6  *
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:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
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
23  * THE SOFTWARE.
24  *
25  **************************************************************************/
26
27 /* LzFind.h -- Match finder for LZ algorithms
28 2008-10-04 : Igor Pavlov : Public domain */
29
30 #ifndef __LZFIND_H
31 #define __LZFIND_H
32
33 #include "lzma_Types.h"
34
35 namespace vogl
36 {
37
38     typedef UInt32 CLzRef;
39
40     typedef struct _CMatchFinder
41     {
42         Byte *buffer;
43         UInt32 pos;
44         UInt32 posLimit;
45         UInt32 streamPos;
46         UInt32 lenLimit;
47
48         UInt32 cyclicBufferPos;
49         UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
50
51         UInt32 matchMaxLen;
52         CLzRef *hash;
53         CLzRef *son;
54         UInt32 hashMask;
55         UInt32 cutValue;
56
57         Byte *bufferBase;
58         ISeqInStream *stream;
59         int streamEndWasReached;
60
61         UInt32 blockSize;
62         UInt32 keepSizeBefore;
63         UInt32 keepSizeAfter;
64
65         UInt32 numHashBytes;
66         int directInput;
67         int btMode;
68         /* int skipModeBits; */
69         int bigHash;
70         UInt32 historySize;
71         UInt32 fixedHashSize;
72         UInt32 hashSizeSum;
73         UInt32 numSons;
74         SRes result;
75         UInt32 crc[256];
76     } CMatchFinder;
77
78 #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
79 #define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])
80
81 #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
82
83     int MatchFinder_NeedMove(CMatchFinder *p);
84     Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
85     void MatchFinder_MoveBlock(CMatchFinder *p);
86     void MatchFinder_ReadIfRequired(CMatchFinder *p);
87
88     void MatchFinder_Construct(CMatchFinder *p);
89
90     /* Conditions:
91      historySize <= 3 GB
92      keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
93 */
94     int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
95                            UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
96                            ISzAlloc *alloc);
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);
100
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);
104
105     /*
106 Conditions:
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
109 */
110
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);
117
118     typedef struct _IMatchFinder
119     {
120         Mf_Init_Func Init;
121         Mf_GetIndexByte_Func GetIndexByte;
122         Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
123         Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
124         Mf_GetMatches_Func GetMatches;
125         Mf_Skip_Func Skip;
126     } IMatchFinder;
127
128     void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
129
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);
135 }
136
137 #endif