LzmaBase.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // LzmaBase.cs
  2. namespace SevenZip.Compression.LZMA
  3. {
  4. internal abstract class Base
  5. {
  6. public const uint kNumRepDistances = 4;
  7. public const uint kNumStates = 12;
  8. // static byte []kLiteralNextStates = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};
  9. // static byte []kMatchNextStates = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
  10. // static byte []kRepNextStates = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
  11. // static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
  12. public struct State
  13. {
  14. public uint Index;
  15. public void Init() { Index = 0; }
  16. public void UpdateChar()
  17. {
  18. if (Index < 4) Index = 0;
  19. else if (Index < 10) Index -= 3;
  20. else Index -= 6;
  21. }
  22. public void UpdateMatch() { Index = (uint)(Index < 7 ? 7 : 10); }
  23. public void UpdateRep() { Index = (uint)(Index < 7 ? 8 : 11); }
  24. public void UpdateShortRep() { Index = (uint)(Index < 7 ? 9 : 11); }
  25. public bool IsCharState() { return Index < 7; }
  26. }
  27. public const int kNumPosSlotBits = 6;
  28. public const int kDicLogSizeMin = 0;
  29. // public const int kDicLogSizeMax = 30;
  30. // public const uint kDistTableSizeMax = kDicLogSizeMax * 2;
  31. public const int kNumLenToPosStatesBits = 2; // it's for speed optimization
  32. public const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits;
  33. public const uint kMatchMinLen = 2;
  34. public static uint GetLenToPosState(uint len)
  35. {
  36. len -= kMatchMinLen;
  37. if (len < kNumLenToPosStates)
  38. return len;
  39. return (uint)(kNumLenToPosStates - 1);
  40. }
  41. public const int kNumAlignBits = 4;
  42. public const uint kAlignTableSize = 1 << kNumAlignBits;
  43. public const uint kAlignMask = (kAlignTableSize - 1);
  44. public const uint kStartPosModelIndex = 4;
  45. public const uint kEndPosModelIndex = 14;
  46. public const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;
  47. public const uint kNumFullDistances = 1 << ((int)kEndPosModelIndex / 2);
  48. public const uint kNumLitPosStatesBitsEncodingMax = 4;
  49. public const uint kNumLitContextBitsMax = 8;
  50. public const int kNumPosStatesBitsMax = 4;
  51. public const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax);
  52. public const int kNumPosStatesBitsEncodingMax = 4;
  53. public const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);
  54. public const int kNumLowLenBits = 3;
  55. public const int kNumMidLenBits = 3;
  56. public const int kNumHighLenBits = 8;
  57. public const uint kNumLowLenSymbols = 1 << kNumLowLenBits;
  58. public const uint kNumMidLenSymbols = 1 << kNumMidLenBits;
  59. public const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +
  60. (1 << kNumHighLenBits);
  61. public const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;
  62. }
  63. }