Debian Codegraph @

plugins/wcx/zip/src/lzma/compression/LZMA/ULZMABase.pas

raw
1 unit ULZMABase;
2
3 {$IFDEF FPC}
4 {$MODE Delphi}
5 {$ENDIF}
6
7 interface
8
9 function StateInit:integer;
10 function StateUpdateChar(const index:integer):integer;
11 function StateUpdateMatch(const index:integer):integer;
12 function StateUpdateRep(const index:integer):integer;
13 function StateUpdateShortRep(const index:integer):integer;
14 function StateIsCharState(const index:integer):boolean;
15 function GetLenToPosState(len:integer):integer;
16
17 const kNumRepDistances = 4;
18 kNumStates = 12;
19 kNumPosSlotBits = 6;
20 kDicLogSizeMin = 0;
21 // kDicLogSizeMax = 28;
22 // kDistTableSizeMax = kDicLogSizeMax * 2;
23
24 kNumLenToPosStatesBits = 2; // it's for speed optimization
25 kNumLenToPosStates = 1 shl kNumLenToPosStatesBits;
26
27 kMatchMinLen = 2;
28
29 kNumAlignBits = 4;
30 kAlignTableSize = 1 shl kNumAlignBits;
31 kAlignMask = (kAlignTableSize - 1);
32
33 kStartPosModelIndex = 4;
34 kEndPosModelIndex = 14;
35 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;
36
37 kNumFullDistances = 1 shl (kEndPosModelIndex div 2);
38
39 kNumLitPosStatesBitsEncodingMax = 4;
40 kNumLitContextBitsMax = 8;
41
42 kNumPosStatesBitsMax = 4;
43 kNumPosStatesMax = (1 shl kNumPosStatesBitsMax);
44 kNumPosStatesBitsEncodingMax = 4;
45 kNumPosStatesEncodingMax = (1 shl kNumPosStatesBitsEncodingMax);
46
47 kNumLowLenBits = 3;
48 kNumMidLenBits = 3;
49 kNumHighLenBits = 8;
50 kNumLowLenSymbols = 1 shl kNumLowLenBits;
51 kNumMidLenSymbols = 1 shl kNumMidLenBits;
52 kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols + (1 shl kNumHighLenBits);
53 kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;
54
55 implementation
56
57 function StateInit:integer;
58 begin
59 result:=0;
60 end;
61
62 function StateUpdateChar(const index:integer):integer;
63 begin
64 if (index < 4) then
65 result:=0
66 else
67 if (index < 10) then
68 result:=index - 3
69 else
70 result:=index - 6;
71 end;
72
73 function StateUpdateMatch(const index:integer):integer;
74 begin
75 if index<7 then result:=7
76 else result:=10;
77 end;
78
79 function StateUpdateRep(const index:integer):integer;
80 begin
81 if index<7 then result:=8
82 else result:=11;
83 end;
84
85 function StateUpdateShortRep(const index:integer):integer;
86 begin
87 if index<7 then result:=9
88 else result:=11;
89 end;
90
91 function StateIsCharState(const index:integer):boolean;
92 begin
93 result:=index<7;
94 end;
95
96 function GetLenToPosState(len:integer):integer;
97 begin
98 len := len - kMatchMinLen;
99 if (len < kNumLenToPosStates) then
100 result:=len
101 else result:=(kNumLenToPosStates - 1);
102 end;
103
104 end.