LzFind.h 3.1 KB

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