LzmaBase.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. namespace SharpCompress.Compressors.LZMA
  2. {
  3. internal abstract class Base
  4. {
  5. public const uint K_NUM_REP_DISTANCES = 4;
  6. public const uint K_NUM_STATES = 12;
  7. // static byte []kLiteralNextStates = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};
  8. // static byte []kMatchNextStates = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
  9. // static byte []kRepNextStates = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
  10. // static byte []kShortRepNextStates = {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
  11. public struct State
  12. {
  13. public uint _index;
  14. public void Init()
  15. {
  16. _index = 0;
  17. }
  18. public void UpdateChar()
  19. {
  20. if (_index < 4)
  21. {
  22. _index = 0;
  23. }
  24. else if (_index < 10)
  25. {
  26. _index -= 3;
  27. }
  28. else
  29. {
  30. _index -= 6;
  31. }
  32. }
  33. public void UpdateMatch()
  34. {
  35. _index = (uint)(_index < 7 ? 7 : 10);
  36. }
  37. public void UpdateRep()
  38. {
  39. _index = (uint)(_index < 7 ? 8 : 11);
  40. }
  41. public void UpdateShortRep()
  42. {
  43. _index = (uint)(_index < 7 ? 9 : 11);
  44. }
  45. public bool IsCharState()
  46. {
  47. return _index < 7;
  48. }
  49. }
  50. public const int K_NUM_POS_SLOT_BITS = 6;
  51. public const int K_DIC_LOG_SIZE_MIN = 0;
  52. // public const int kDicLogSizeMax = 30;
  53. // public const uint kDistTableSizeMax = kDicLogSizeMax * 2;
  54. public const int K_NUM_LEN_TO_POS_STATES_BITS = 2; // it's for speed optimization
  55. public const uint K_NUM_LEN_TO_POS_STATES = 1 << K_NUM_LEN_TO_POS_STATES_BITS;
  56. public const uint K_MATCH_MIN_LEN = 2;
  57. public static uint GetLenToPosState(uint len)
  58. {
  59. len -= K_MATCH_MIN_LEN;
  60. if (len < K_NUM_LEN_TO_POS_STATES)
  61. {
  62. return len;
  63. }
  64. return K_NUM_LEN_TO_POS_STATES - 1;
  65. }
  66. public const int K_NUM_ALIGN_BITS = 4;
  67. public const uint K_ALIGN_TABLE_SIZE = 1 << K_NUM_ALIGN_BITS;
  68. public const uint K_ALIGN_MASK = (K_ALIGN_TABLE_SIZE - 1);
  69. public const uint K_START_POS_MODEL_INDEX = 4;
  70. public const uint K_END_POS_MODEL_INDEX = 14;
  71. public const uint K_NUM_POS_MODELS = K_END_POS_MODEL_INDEX - K_START_POS_MODEL_INDEX;
  72. public const uint K_NUM_FULL_DISTANCES = 1 << ((int)K_END_POS_MODEL_INDEX / 2);
  73. public const uint K_NUM_LIT_POS_STATES_BITS_ENCODING_MAX = 4;
  74. public const uint K_NUM_LIT_CONTEXT_BITS_MAX = 8;
  75. public const int K_NUM_POS_STATES_BITS_MAX = 4;
  76. public const uint K_NUM_POS_STATES_MAX = (1 << K_NUM_POS_STATES_BITS_MAX);
  77. public const int K_NUM_POS_STATES_BITS_ENCODING_MAX = 4;
  78. public const uint K_NUM_POS_STATES_ENCODING_MAX = (1 << K_NUM_POS_STATES_BITS_ENCODING_MAX);
  79. public const int K_NUM_LOW_LEN_BITS = 3;
  80. public const int K_NUM_MID_LEN_BITS = 3;
  81. public const int K_NUM_HIGH_LEN_BITS = 8;
  82. public const uint K_NUM_LOW_LEN_SYMBOLS = 1 << K_NUM_LOW_LEN_BITS;
  83. public const uint K_NUM_MID_LEN_SYMBOLS = 1 << K_NUM_MID_LEN_BITS;
  84. public const uint K_NUM_LEN_SYMBOLS = K_NUM_LOW_LEN_SYMBOLS + K_NUM_MID_LEN_SYMBOLS +
  85. (1 << K_NUM_HIGH_LEN_BITS);
  86. public const uint K_MATCH_MAX_LEN = K_MATCH_MIN_LEN + K_NUM_LEN_SYMBOLS - 1;
  87. }
  88. }