MatchFinder.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* MatchFinder.h */
  2. #ifndef __MATCHFINDER_H
  3. #define __MATCHFINDER_H
  4. #include "../../IStream.h"
  5. typedef UInt32 CLzRef;
  6. typedef struct _CMatchFinder
  7. {
  8. Byte *buffer;
  9. UInt32 pos;
  10. UInt32 posLimit;
  11. UInt32 streamPos;
  12. UInt32 lenLimit;
  13. UInt32 cyclicBufferPos;
  14. UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
  15. UInt32 matchMaxLen;
  16. CLzRef *hash;
  17. CLzRef *son;
  18. UInt32 hashMask;
  19. UInt32 cutValue;
  20. Byte *bufferBase;
  21. ISeqInStream *stream;
  22. int streamEndWasReached;
  23. UInt32 blockSize;
  24. UInt32 keepSizeBefore;
  25. UInt32 keepSizeAfter;
  26. UInt32 numHashBytes;
  27. int directInput;
  28. int btMode;
  29. /* int skipModeBits; */
  30. int bigHash;
  31. UInt32 historySize;
  32. UInt32 fixedHashSize;
  33. UInt32 hashSizeSum;
  34. UInt32 numSons;
  35. HRes result;
  36. } CMatchFinder;
  37. #define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
  38. #define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])
  39. #define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
  40. int MatchFinder_NeedMove(CMatchFinder *p);
  41. Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
  42. void MatchFinder_MoveBlock(CMatchFinder *p);
  43. void MatchFinder_ReadIfRequired(CMatchFinder *p);
  44. void MatchFinder_Construct(CMatchFinder *p);
  45. /* Conditions:
  46. historySize <= 3 GB
  47. keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
  48. */
  49. int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
  50. UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
  51. ISzAlloc *alloc);
  52. void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
  53. void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
  54. void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
  55. UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
  56. UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
  57. UInt32 *distances, UInt32 maxLen);
  58. /*
  59. Conditions:
  60. Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
  61. Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
  62. */
  63. typedef void (*Mf_Init_Func)(void *object);
  64. typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);
  65. typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
  66. typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
  67. typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
  68. typedef void (*Mf_Skip_Func)(void *object, UInt32);
  69. typedef struct _IMatchFinder
  70. {
  71. Mf_Init_Func Init;
  72. Mf_GetIndexByte_Func GetIndexByte;
  73. Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
  74. Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
  75. Mf_GetMatches_Func GetMatches;
  76. Mf_Skip_Func Skip;
  77. } IMatchFinder;
  78. void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
  79. void MatchFinder_Init(CMatchFinder *p);
  80. UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
  81. UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
  82. void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
  83. void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
  84. #endif