LZMA.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // LZMA.h
  2. #ifndef __LZMA_H
  3. #define __LZMA_H
  4. namespace NCompress {
  5. namespace NLZMA {
  6. const UInt32 kNumRepDistances = 4;
  7. const int kNumStates = 12;
  8. const Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};
  9. const Byte kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
  10. const Byte kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
  11. const Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
  12. class CState
  13. {
  14. public:
  15. Byte Index;
  16. void Init() { Index = 0; }
  17. void UpdateChar() { Index = kLiteralNextStates[Index]; }
  18. void UpdateMatch() { Index = kMatchNextStates[Index]; }
  19. void UpdateRep() { Index = kRepNextStates[Index]; }
  20. void UpdateShortRep() { Index = kShortRepNextStates[Index]; }
  21. bool IsCharState() const { return Index < 7; }
  22. };
  23. const int kNumPosSlotBits = 6;
  24. const int kDicLogSizeMin = 0;
  25. const int kDicLogSizeMax = 32;
  26. const int kDistTableSizeMax = kDicLogSizeMax * 2;
  27. const UInt32 kNumLenToPosStates = 4;
  28. inline UInt32 GetLenToPosState(UInt32 len)
  29. {
  30. len -= 2;
  31. if (len < kNumLenToPosStates)
  32. return len;
  33. return kNumLenToPosStates - 1;
  34. }
  35. namespace NLength {
  36. const int kNumPosStatesBitsMax = 4;
  37. const UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax);
  38. const int kNumPosStatesBitsEncodingMax = 4;
  39. const UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);
  40. const int kNumLowBits = 3;
  41. const int kNumMidBits = 3;
  42. const int kNumHighBits = 8;
  43. const UInt32 kNumLowSymbols = 1 << kNumLowBits;
  44. const UInt32 kNumMidSymbols = 1 << kNumMidBits;
  45. const UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);
  46. }
  47. const UInt32 kMatchMinLen = 2;
  48. const UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;
  49. const int kNumAlignBits = 4;
  50. const UInt32 kAlignTableSize = 1 << kNumAlignBits;
  51. const UInt32 kAlignMask = (kAlignTableSize - 1);
  52. const UInt32 kStartPosModelIndex = 4;
  53. const UInt32 kEndPosModelIndex = 14;
  54. const UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;
  55. const UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2);
  56. const int kNumLitPosStatesBitsEncodingMax = 4;
  57. const int kNumLitContextBitsMax = 8;
  58. const int kNumMoveBits = 5;
  59. }}
  60. #endif