| 1 |
/* LzFind.h -- Match finder for LZ algorithms |
| 2 |
2008-10-04 : Igor Pavlov : Public domain */ |
| 3 |
// ---------------------------------------------------------------------------- |
| 4 |
// Copyright (C) 2014 |
| 5 |
// David Freese, W1HKJ |
| 6 |
// |
| 7 |
// This file is part of flmsg |
| 8 |
// |
| 9 |
// flrig is free software; you can redistribute it and/or modify |
| 10 |
// it under the terms of the GNU General Public License as published by |
| 11 |
// the Free Software Foundation; either version 3 of the License, or |
| 12 |
// (at your option) any later version. |
| 13 |
// |
| 14 |
// flrig is distributed in the hope that it will be useful, |
| 15 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
// GNU General Public License for more details. |
| 18 |
// |
| 19 |
// You should have received a copy of the GNU General Public License |
| 20 |
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
// ---------------------------------------------------------------------------- |
| 22 |
|
| 23 |
#ifndef __LZFIND_H |
| 24 |
#define __LZFIND_H |
| 25 |
|
| 26 |
#include "Types.h" |
| 27 |
|
| 28 |
typedef LZ_UInt32 CLzRef; |
| 29 |
|
| 30 |
typedef struct _CMatchFinder |
| 31 |
{ |
| 32 |
Byte *buffer; |
| 33 |
LZ_UInt32 pos; |
| 34 |
LZ_UInt32 posLimit; |
| 35 |
LZ_UInt32 streamPos; |
| 36 |
LZ_UInt32 lenLimit; |
| 37 |
|
| 38 |
LZ_UInt32 cyclicBufferPos; |
| 39 |
LZ_UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */ |
| 40 |
|
| 41 |
LZ_UInt32 matchMaxLen; |
| 42 |
CLzRef *hash; |
| 43 |
CLzRef *son; |
| 44 |
LZ_UInt32 hashMask; |
| 45 |
LZ_UInt32 cutValue; |
| 46 |
|
| 47 |
Byte *bufferBase; |
| 48 |
ISeqInStream *stream; |
| 49 |
int streamEndWasReached; |
| 50 |
|
| 51 |
LZ_UInt32 blockSize; |
| 52 |
LZ_UInt32 keepSizeBefore; |
| 53 |
LZ_UInt32 keepSizeAfter; |
| 54 |
|
| 55 |
LZ_UInt32 numHashBytes; |
| 56 |
int directInput; |
| 57 |
int btMode; |
| 58 |
/* int skipModeBits; */ |
| 59 |
int bigHash; |
| 60 |
LZ_UInt32 historySize; |
| 61 |
LZ_UInt32 fixedHashSize; |
| 62 |
LZ_UInt32 hashSizeSum; |
| 63 |
LZ_UInt32 numSons; |
| 64 |
SRes result; |
| 65 |
LZ_UInt32 crc[256]; |
| 66 |
} CMatchFinder; |
| 67 |
|
| 68 |
#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer) |
| 69 |
#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(LZ_Int32)(index)]) |
| 70 |
|
| 71 |
#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos) |
| 72 |
|
| 73 |
int MatchFinder_NeedMove(CMatchFinder *p); |
| 74 |
Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p); |
| 75 |
void MatchFinder_MoveBlock(CMatchFinder *p); |
| 76 |
void MatchFinder_ReadIfRequired(CMatchFinder *p); |
| 77 |
|
| 78 |
void MatchFinder_Construct(CMatchFinder *p); |
| 79 |
|
| 80 |
/* Conditions: |
| 81 |
historySize <= 3 GB |
| 82 |
keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB |
| 83 |
*/ |
| 84 |
int MatchFinder_Create(CMatchFinder *p, LZ_UInt32 historySize, |
| 85 |
LZ_UInt32 keepAddBufferBefore, LZ_UInt32 matchMaxLen, LZ_UInt32 keepAddBufferAfter, |
| 86 |
ISzAlloc *alloc); |
| 87 |
void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc); |
| 88 |
void MatchFinder_Normalize3(LZ_UInt32 subValue, CLzRef *items, LZ_UInt32 numItems); |
| 89 |
void MatchFinder_ReduceOffsets(CMatchFinder *p, LZ_UInt32 subValue); |
| 90 |
|
| 91 |
LZ_UInt32 * GetMatchesSpec1(LZ_UInt32 lenLimit, LZ_UInt32 curMatch, LZ_UInt32 pos, const Byte *buffer, CLzRef *son, |
| 92 |
LZ_UInt32 _cyclicBufferPos, LZ_UInt32 _cyclicBufferSize, LZ_UInt32 _cutValue, |
| 93 |
LZ_UInt32 *distances, LZ_UInt32 maxLen); |
| 94 |
|
| 95 |
/* |
| 96 |
Conditions: |
| 97 |
Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func. |
| 98 |
Mf_GetPointerToCurrentPos_Func's result must be used only before any other function |
| 99 |
*/ |
| 100 |
|
| 101 |
typedef void (*Mf_Init_Func)(void *object); |
| 102 |
typedef Byte (*Mf_GetIndexByte_Func)(void *object, LZ_Int32 index); |
| 103 |
typedef LZ_UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object); |
| 104 |
typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object); |
| 105 |
typedef LZ_UInt32 (*Mf_GetMatches_Func)(void *object, LZ_UInt32 *distances); |
| 106 |
typedef void (*Mf_Skip_Func)(void *object, LZ_UInt32); |
| 107 |
|
| 108 |
typedef struct _IMatchFinder |
| 109 |
{ |
| 110 |
Mf_Init_Func Init; |
| 111 |
Mf_GetIndexByte_Func GetIndexByte; |
| 112 |
Mf_GetNumAvailableBytes_Func GetNumAvailableBytes; |
| 113 |
Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos; |
| 114 |
Mf_GetMatches_Func GetMatches; |
| 115 |
Mf_Skip_Func Skip; |
| 116 |
} IMatchFinder; |
| 117 |
|
| 118 |
void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable); |
| 119 |
|
| 120 |
void MatchFinder_Init(CMatchFinder *p); |
| 121 |
LZ_UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, LZ_UInt32 *distances); |
| 122 |
LZ_UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, LZ_UInt32 *distances); |
| 123 |
void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, LZ_UInt32 num); |
| 124 |
void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, LZ_UInt32 num); |
| 125 |
|
| 126 |
#endif |