LzFind.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* LzFind.h -- Match finder for LZ algorithms
  2. 2017-06-10 : Igor Pavlov : Public domain */
  3. #ifndef __LZ_FIND_H
  4. #define __LZ_FIND_H
  5. #include "7zTypes.h"
  6. EXTERN_C_BEGIN
  7. typedef UInt32 CLzRef;
  8. typedef struct _CMatchFinder
  9. {
  10. Byte *buffer;
  11. UInt32 pos;
  12. UInt32 posLimit;
  13. UInt32 streamPos;
  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 *bufferBase;
  27. ISeqInStream *stream;
  28. UInt32 blockSize;
  29. UInt32 keepSizeBefore;
  30. UInt32 keepSizeAfter;
  31. UInt32 numHashBytes;
  32. size_t directInputRem;
  33. UInt32 historySize;
  34. UInt32 fixedHashSize;
  35. UInt32 hashSizeSum;
  36. SRes result;
  37. UInt32 crc[256];
  38. size_t numRefs;
  39. UInt64 expectedDataSize;
  40. } CMatchFinder;
  41. #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
  42. #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
  43. #define Inline_MatchFinder_IsFinishedOK(p) \
  44. ((p)->streamEndWasReached \
  45. && (p)->streamPos == (p)->pos \
  46. && (!(p)->directInput || (p)->directInputRem == 0))
  47. int MatchFinder_NeedMove(CMatchFinder *p);
  48. Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
  49. void MatchFinder_MoveBlock(CMatchFinder *p);
  50. void MatchFinder_ReadIfRequired(CMatchFinder *p);
  51. void MatchFinder_Construct(CMatchFinder *p);
  52. /* Conditions:
  53. historySize <= 3 GB
  54. keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
  55. */
  56. int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
  57. UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
  58. ISzAllocPtr alloc);
  59. void MatchFinder_Free(CMatchFinder *p, ISzAllocPtr alloc);
  60. void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems);
  61. void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
  62. UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
  63. UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
  64. UInt32 *distances, UInt32 maxLen);
  65. /*
  66. Conditions:
  67. Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
  68. Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
  69. */
  70. typedef void (*Mf_Init_Func)(void *object);
  71. typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
  72. typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
  73. typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
  74. typedef void (*Mf_Skip_Func)(void *object, UInt32);
  75. typedef struct _IMatchFinder
  76. {
  77. Mf_Init_Func Init;
  78. Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
  79. Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
  80. Mf_GetMatches_Func GetMatches;
  81. Mf_Skip_Func Skip;
  82. } IMatchFinder;
  83. void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
  84. void MatchFinder_Init_LowHash(CMatchFinder *p);
  85. void MatchFinder_Init_HighHash(CMatchFinder *p);
  86. void MatchFinder_Init_3(CMatchFinder *p, int readData);
  87. void MatchFinder_Init(CMatchFinder *p);
  88. UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
  89. UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
  90. void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
  91. void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
  92. EXTERN_C_END
  93. #endif