Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.2 KiB

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