1// LZMA.h 2 3#ifndef __LZMA_H 4#define __LZMA_H 5 6namespace NCompress { 7namespace NLZMA { 8 9const UInt32 kNumRepDistances = 4; 10 11const int kNumStates = 12; 12 13const Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5}; 14const Byte kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10}; 15const Byte kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11}; 16const Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11}; 17 18class CState 19{ 20public: 21 Byte Index; 22 void Init() { Index = 0; } 23 void UpdateChar() { Index = kLiteralNextStates[Index]; } 24 void UpdateMatch() { Index = kMatchNextStates[Index]; } 25 void UpdateRep() { Index = kRepNextStates[Index]; } 26 void UpdateShortRep() { Index = kShortRepNextStates[Index]; } 27 bool IsCharState() const { return Index < 7; } 28}; 29 30const int kNumPosSlotBits = 6; 31const int kDicLogSizeMin = 0; 32const int kDicLogSizeMax = 32; 33const int kDistTableSizeMax = kDicLogSizeMax * 2; 34 35const UInt32 kNumLenToPosStates = 4; 36 37inline UInt32 GetLenToPosState(UInt32 len) 38{ 39 len -= 2; 40 if (len < kNumLenToPosStates) 41 return len; 42 return kNumLenToPosStates - 1; 43} 44 45namespace NLength { 46 47const int kNumPosStatesBitsMax = 4; 48const UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax); 49 50const int kNumPosStatesBitsEncodingMax = 4; 51const UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax); 52 53const int kNumLowBits = 3; 54const int kNumMidBits = 3; 55const int kNumHighBits = 8; 56const UInt32 kNumLowSymbols = 1 << kNumLowBits; 57const UInt32 kNumMidSymbols = 1 << kNumMidBits; 58const UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits); 59 60} 61 62const UInt32 kMatchMinLen = 2; 63const UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1; 64 65const int kNumAlignBits = 4; 66const UInt32 kAlignTableSize = 1 << kNumAlignBits; 67const UInt32 kAlignMask = (kAlignTableSize - 1); 68 69const UInt32 kStartPosModelIndex = 4; 70const UInt32 kEndPosModelIndex = 14; 71const UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex; 72 73const UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2); 74 75const int kNumLitPosStatesBitsEncodingMax = 4; 76const int kNumLitContextBitsMax = 8; 77 78const int kNumMoveBits = 5; 79 80}} 81 82#endif 83