LzFind.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* LzFind.h -- Match finder for LZ algorithms
  2. 2015-10-15 : 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. } CMatchFinder;
  40. #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
  41. #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
  42. #define Inline_MatchFinder_IsFinishedOK(p) \
  43. ((p)->streamEndWasReached \
  44. && (p)->streamPos == (p)->pos \
  45. && (!(p)->directInput || (p)->directInputRem == 0))
  46. int MatchFinder_NeedMove(CMatchFinder *p);
  47. Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
  48. void MatchFinder_MoveBlock(CMatchFinder *p);
  49. void MatchFinder_ReadIfRequired(CMatchFinder *p);
  50. void MatchFinder_Construct(CMatchFinder *p);
  51. /* Conditions:
  52. historySize <= 3 GB
  53. keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
  54. */
  55. int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
  56. UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
  57. ISzAlloc *alloc);
  58. void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
  59. void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems);
  60. void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
  61. UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
  62. UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
  63. UInt32 *distances, UInt32 maxLen);
  64. /*
  65. Conditions:
  66. Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
  67. Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
  68. */
  69. typedef void (*Mf_Init_Func)(void *object);
  70. typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
  71. typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
  72. typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
  73. typedef void (*Mf_Skip_Func)(void *object, UInt32);
  74. typedef struct _IMatchFinder
  75. {
  76. Mf_Init_Func Init;
  77. Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
  78. Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
  79. Mf_GetMatches_Func GetMatches;
  80. Mf_Skip_Func Skip;
  81. } IMatchFinder;
  82. void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
  83. void MatchFinder_Init_2(CMatchFinder *p, int readData);
  84. void MatchFinder_Init(CMatchFinder *p);
  85. UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
  86. UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
  87. void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
  88. void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
  89. EXTERN_C_END
  90. #endif