tables.mx raw
1 // RFC 1951 constant tables.
2 //
3 // They used to be array literals inside the functions that use them, in three
4 // cases duplicated between the encoder and the decoder - a 256-entry literal
5 // per call in lengthCode/offsetCode, which run once per token. Package-level
6 // variables cannot have initialisers and the package has exactly one init
7 // (deflate.mx), so initTables fills them once.
8 package flate
9
10 var (
11 codegenOrder []uint32
12 lengthExtraBits []int8
13 offsetExtraBits []int8
14 lengthBase []uint32
15 offsetBase []uint32
16 codeOrder []int32
17 lengthCodes []uint32
18 offsetCodes []uint32
19 )
20
21 // initTables fills the RFC 1951 tables. Called from the package init.
22 func initTables() {
23 codegenOrder = []uint32{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}
24
25 lengthExtraBits = []int8{
26 /* 257 */ 0, 0, 0,
27 /* 260 */ 0, 0, 0, 0, 0, 1, 1, 1, 1, 2,
28 /* 270 */ 2, 2, 2, 3, 3, 3, 3, 4, 4, 4,
29 /* 280 */ 4, 5, 5, 5, 5, 0,}
30
31 offsetExtraBits = []int8{
32 0, 0, 0, 0, 1, 1, 2, 2, 3, 3,
33 4, 4, 5, 5, 6, 6, 7, 7, 8, 8,
34 9, 9, 10, 10, 11, 11, 12, 12, 13, 13,}
35
36 lengthBase = []uint32{
37 0, 1, 2, 3, 4, 5, 6, 7, 8, 10,
38 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
39 64, 80, 96, 112, 128, 160, 192, 224, 255,}
40
41 offsetBase = []uint32{
42 0x000000, 0x000001, 0x000002, 0x000003, 0x000004,
43 0x000006, 0x000008, 0x00000c, 0x000010, 0x000018,
44 0x000020, 0x000030, 0x000040, 0x000060, 0x000080,
45 0x0000c0, 0x000100, 0x000180, 0x000200, 0x000300,
46 0x000400, 0x000600, 0x000800, 0x000c00, 0x001000,
47 0x001800, 0x002000, 0x003000, 0x004000, 0x006000,}
48
49 codeOrder = []int32{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}
50
51 lengthCodes = []uint32{
52 0, 1, 2, 3, 4, 5, 6, 7, 8, 8,
53 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
54 13, 13, 13, 13, 14, 14, 14, 14, 15, 15,
55 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
56 17, 17, 17, 17, 17, 17, 17, 17, 18, 18,
57 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
58 19, 19, 19, 19, 20, 20, 20, 20, 20, 20,
59 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
60 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
61 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
62 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
63 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
64 23, 23, 23, 23, 23, 23, 23, 23, 24, 24,
65 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
66 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
67 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
68 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
69 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
70 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
71 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
72 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
73 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
74 26, 26, 26, 26, 27, 27, 27, 27, 27, 27,
75 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
76 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
77 27, 27, 27, 27, 27, 28,}
78
79 offsetCodes = []uint32{
80 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,
81 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
82 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
83 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
84 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
85 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
86 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
87 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
88 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
89 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
90 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
91 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
92 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
93 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
94 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
95 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,}
96
97 }
98