LzFind.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* LzFind.h -- Match finder for LZ algorithms
  2. 2024-01-22 : Igor Pavlov : Public domain */
  3. #ifndef ZIP7_INC_LZ_FIND_H
  4. #define ZIP7_INC_LZ_FIND_H
  5. #include "7zTypes.h"
  6. EXTERN_C_BEGIN
  7. typedef UInt32 CLzRef;
  8. typedef struct
  9. {
  10. const Byte *buffer;
  11. UInt32 pos;
  12. UInt32 posLimit;
  13. UInt32 streamPos; /* wrap over Zero is allowed (streamPos < pos). Use (UInt32)(streamPos - pos) */
  14. UInt32 lenLimit;
  15. UInt32 cyclicBufferPos;
  16. UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
  17. Byte streamEndWasReached;
  18. Byte btMode;
  19. Byte bigHash;
  20. Byte directInput;
  21. UInt32 matchMaxLen;
  22. CLzRef *hash;
  23. CLzRef *son;
  24. UInt32 hashMask;
  25. UInt32 cutValue;
  26. Byte *bufBase;
  27. ISeqInStreamPtr stream;
  28. UInt32 blockSize;
  29. UInt32 keepSizeBefore;
  30. UInt32 keepSizeAfter;
  31. UInt32 numHashBytes;
  32. size_t directInputRem;
  33. UInt32 historySize;
  34. UInt32 fixedHashSize;
  35. Byte numHashBytes_Min;
  36. Byte numHashOutBits;
  37. Byte _pad2_[2];
  38. SRes result;
  39. UInt32 crc[256];
  40. size_t numRefs;
  41. UInt64 expectedDataSize;
  42. } CMatchFinder;
  43. #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((const Byte *)(p)->buffer)
  44. #define Inline_MatchFinder_GetNumAvailableBytes(p) ((UInt32)((p)->streamPos - (p)->pos))
  45. /*
  46. #define Inline_MatchFinder_IsFinishedOK(p) \
  47. ((p)->streamEndWasReached \
  48. && (p)->streamPos == (p)->pos \
  49. && (!(p)->directInput || (p)->directInputRem == 0))
  50. */
  51. int MatchFinder_NeedMove(CMatchFinder *p);
  52. /* Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p); */
  53. void MatchFinder_MoveBlock(CMatchFinder *p);
  54. void MatchFinder_ReadIfRequired(CMatchFinder *p);
  55. void MatchFinder_Construct(CMatchFinder *p);
  56. /* (directInput = 0) is default value.
  57. It's required to provide correct (directInput) value
  58. before calling MatchFinder_Create().
  59. You can set (directInput) by any of the following calls:
  60. - MatchFinder_SET_DIRECT_INPUT_BUF()
  61. - MatchFinder_SET_STREAM()
  62. - MatchFinder_SET_STREAM_MODE()
  63. */
  64. #define MatchFinder_SET_DIRECT_INPUT_BUF(p, _src_, _srcLen_) { \
  65. (p)->stream = NULL; \
  66. (p)->directInput = 1; \
  67. (p)->buffer = (_src_); \
  68. (p)->directInputRem = (_srcLen_); }
  69. /*
  70. #define MatchFinder_SET_STREAM_MODE(p) { \
  71. (p)->directInput = 0; }
  72. */
  73. #define MatchFinder_SET_STREAM(p, _stream_) { \
  74. (p)->stream = _stream_; \
  75. (p)->directInput = 0; }
  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. /*
  82. #define MatchFinder_INIT_POS(p, val) \
  83. (p)->pos = (val); \
  84. (p)->streamPos = (val);
  85. */
  86. // void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
  87. #define MatchFinder_REDUCE_OFFSETS(p, subValue) \
  88. (p)->pos -= (subValue); \
  89. (p)->streamPos -= (subValue);
  90. UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
  91. size_t _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
  92. UInt32 *distances, UInt32 maxLen);
  93. /*
  94. Conditions:
  95. Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
  96. Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
  97. */
  98. typedef void (*Mf_Init_Func)(void *object);
  99. typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
  100. typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
  101. typedef UInt32 * (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
  102. typedef void (*Mf_Skip_Func)(void *object, UInt32);
  103. typedef struct
  104. {
  105. Mf_Init_Func Init;
  106. Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
  107. Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
  108. Mf_GetMatches_Func GetMatches;
  109. Mf_Skip_Func Skip;
  110. } IMatchFinder2;
  111. void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder2 *vTable);
  112. void MatchFinder_Init_LowHash(CMatchFinder *p);
  113. void MatchFinder_Init_HighHash(CMatchFinder *p);
  114. void MatchFinder_Init_4(CMatchFinder *p);
  115. // void MatchFinder_Init(CMatchFinder *p);
  116. void MatchFinder_Init(void *p);
  117. UInt32* Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
  118. UInt32* Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
  119. void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
  120. void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
  121. void LzFindPrepare(void);
  122. EXTERN_C_END
  123. #endif