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