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