LzmaBase.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* This file is part of SevenZipSharp.
  2. SevenZipSharp is free software: you can redistribute it and/or modify
  3. it under the terms of the GNU Lesser General Public License as published by
  4. the Free Software Foundation, either version 3 of the License, or
  5. (at your option) any later version.
  6. SevenZipSharp is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU Lesser General Public License for more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with SevenZipSharp. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. namespace SevenZip.Sdk.Compression.Lzma
  14. {
  15. internal abstract class Base
  16. {
  17. public const uint kAlignMask = (kAlignTableSize - 1);
  18. public const uint kAlignTableSize = 1 << kNumAlignBits;
  19. public const int kDicLogSizeMin = 0;
  20. public const uint kEndPosModelIndex = 14;
  21. public const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;
  22. // public const int kDicLogSizeMax = 30;
  23. // public const uint kDistTableSizeMax = kDicLogSizeMax * 2;
  24. public const uint kMatchMinLen = 2;
  25. public const int kNumAlignBits = 4;
  26. public const uint kNumFullDistances = 1 << ((int) kEndPosModelIndex/2);
  27. public const int kNumHighLenBits = 8;
  28. public const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +
  29. (1 << kNumHighLenBits);
  30. public const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits;
  31. public const int kNumLenToPosStatesBits = 2; // it's for speed optimization
  32. public const uint kNumLitContextBitsMax = 8;
  33. public const uint kNumLitPosStatesBitsEncodingMax = 4;
  34. public const int kNumLowLenBits = 3;
  35. public const uint kNumLowLenSymbols = 1 << kNumLowLenBits;
  36. public const int kNumMidLenBits = 3;
  37. public const uint kNumMidLenSymbols = 1 << kNumMidLenBits;
  38. public const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;
  39. public const int kNumPosSlotBits = 6;
  40. public const int kNumPosStatesBitsEncodingMax = 4;
  41. public const int kNumPosStatesBitsMax = 4;
  42. public const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);
  43. public const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax);
  44. public const uint kNumRepDistances = 4;
  45. public const uint kNumStates = 12;
  46. public const uint kStartPosModelIndex = 4;
  47. public static uint GetLenToPosState(uint len)
  48. {
  49. len -= kMatchMinLen;
  50. if (len < kNumLenToPosStates)
  51. return len;
  52. return (kNumLenToPosStates - 1);
  53. }
  54. #region Nested type: State
  55. public struct State
  56. {
  57. public uint Index;
  58. public void Init()
  59. {
  60. Index = 0;
  61. }
  62. public void UpdateChar()
  63. {
  64. if (Index < 4) Index = 0;
  65. else if (Index < 10) Index -= 3;
  66. else Index -= 6;
  67. }
  68. public void UpdateMatch()
  69. {
  70. Index = (uint) (Index < 7 ? 7 : 10);
  71. }
  72. public void UpdateRep()
  73. {
  74. Index = (uint) (Index < 7 ? 8 : 11);
  75. }
  76. public void UpdateShortRep()
  77. {
  78. Index = (uint) (Index < 7 ? 9 : 11);
  79. }
  80. public bool IsCharState()
  81. {
  82. return Index < 7;
  83. }
  84. }
  85. #endregion
  86. }
  87. }