other-licenses/7zstub/src/7zip/Compress/LZMA/LZMA.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial