1 /* LzFind.h -- Match finder for LZ algorithms 2 2021-07-13 : Igor Pavlov : Public domain */ 3 4 #ifndef __LZ_FIND_H 5 #define __LZ_FIND_H 6 7 #include "7zTypes.h" 8 9 EXTERN_C_BEGIN 10 11 typedef UInt32 CLzRef; 12 13 typedef struct _CMatchFinder 14 { 15 Byte *buffer; 16 UInt32 pos; 17 UInt32 posLimit; 18 UInt32 streamPos; /* wrap over Zero is allowed (streamPos < pos). Use (UInt32)(streamPos - pos) */ 19 UInt32 lenLimit; 20 21 UInt32 cyclicBufferPos; 22 UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */ 23 24 Byte streamEndWasReached; 25 Byte btMode; 26 Byte bigHash; 27 Byte directInput; 28 29 UInt32 matchMaxLen; 30 CLzRef *hash; 31 CLzRef *son; 32 UInt32 hashMask; 33 UInt32 cutValue; 34 35 Byte *bufferBase; 36 ISeqInStream *stream; 37 38 UInt32 blockSize; 39 UInt32 keepSizeBefore; 40 UInt32 keepSizeAfter; 41 42 UInt32 numHashBytes; 43 size_t directInputRem; 44 UInt32 historySize; 45 UInt32 fixedHashSize; 46 UInt32 hashSizeSum; 47 SRes result; 48 UInt32 crc[256]; 49 size_t numRefs; 50 51 UInt64 expectedDataSize; 52 } CMatchFinder; 53 54 #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((const Byte *)(p)->buffer) 55 56 #define Inline_MatchFinder_GetNumAvailableBytes(p) ((UInt32)((p)->streamPos - (p)->pos)) 57 58 /* 59 #define Inline_MatchFinder_IsFinishedOK(p) \ 60 ((p)->streamEndWasReached \ 61 && (p)->streamPos == (p)->pos \ 62 && (!(p)->directInput || (p)->directInputRem == 0)) 63 */ 64 65 int MatchFinder_NeedMove(CMatchFinder *p); 66 /* Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p); */ 67 void MatchFinder_MoveBlock(CMatchFinder *p); 68 void MatchFinder_ReadIfRequired(CMatchFinder *p); 69 70 void MatchFinder_Construct(CMatchFinder *p); 71 72 /* Conditions: 73 historySize <= 3 GB 74 keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB 75 */ 76 int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, 77 UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, 78 ISzAllocPtr alloc); 79 void MatchFinder_Free(CMatchFinder *p, ISzAllocPtr alloc); 80 void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems); 81 // void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue); 82 83 /* 84 #define Inline_MatchFinder_InitPos(p, val) \ 85 (p)->pos = (val); \ 86 (p)->streamPos = (val); 87 */ 88 89 #define Inline_MatchFinder_ReduceOffsets(p, subValue) \ 90 (p)->pos -= (subValue); \ 91 (p)->streamPos -= (subValue); 92 93 94 UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son, 95 size_t _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, 96 UInt32 *distances, UInt32 maxLen); 97 98 /* 99 Conditions: 100 Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func. 101 Mf_GetPointerToCurrentPos_Func's result must be used only before any other function 102 */ 103 104 typedef void (*Mf_Init_Func)(void *object); 105 typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object); 106 typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object); 107 typedef UInt32 * (*Mf_GetMatches_Func)(void *object, UInt32 *distances); 108 typedef void (*Mf_Skip_Func)(void *object, UInt32); 109 110 typedef struct _IMatchFinder 111 { 112 Mf_Init_Func Init; 113 Mf_GetNumAvailableBytes_Func GetNumAvailableBytes; 114 Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos; 115 Mf_GetMatches_Func GetMatches; 116 Mf_Skip_Func Skip; 117 } IMatchFinder2; 118 119 void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder2 *vTable); 120 121 void MatchFinder_Init_LowHash(CMatchFinder *p); 122 void MatchFinder_Init_HighHash(CMatchFinder *p); 123 void MatchFinder_Init_4(CMatchFinder *p); 124 void MatchFinder_Init(CMatchFinder *p); 125 126 UInt32* Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); 127 UInt32* Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); 128 129 void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); 130 void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); 131 132 void LzFindPrepare(void); 133 134 EXTERN_C_END 135 136 #endif 137