-
Notifications
You must be signed in to change notification settings - Fork 0
/
table.go
110 lines (95 loc) · 2.65 KB
/
table.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package ilog10
var factors = [...]uint64{
1e19,
1e18,
1e17,
1e16,
1e15,
1e14,
1e13,
1e12,
1e11,
1e10,
1e9,
1e8,
1e7,
1e6,
1e5,
1e4,
1e3,
1e2,
1e1,
}
const factorsCount = len(factors)
const maxUint64 = ^uint64(0)
const maxUint32 = ^uint32(0)
var lookup32 [32]uint32
var lookup64 [64]uint64
func init() {
buildLookup32()
buildLookup64()
}
func buildLookup32() {
/*
lookup32 table
4294967295 4294967295
1000000000 4294967295 4294967295
100000000 4294967295 4294967295
10000000 4294967295 4294967295 4294967295
1000000 4294967295 4294967295
100000 4294967295 4294967295
10000 4294967295 4294967295 4294967295
1000 4294967295 4294967295
100 4294967295 4294967295
10 4294967295 4294967295 4294967295
*/
for i, j := 10, 0; i < factorsCount; i++ {
if i == 10 {
lookup32[j] = maxUint32
lookup32[j+1] = maxUint32
j += 2
}
lookup32[j] = uint32(factors[i])
lookup32[j+1] = maxUint32
lookup32[j+2] = maxUint32
j += 3
if i%3 == 0 {
lookup32[j] = maxUint32
j++
}
}
}
func buildLookup64() {
/*
lookup64 table
10000000000000000000 18446744073709551615 18446744073709551615 18446744073709551615
1000000000000000000 18446744073709551615 18446744073709551615
100000000000000000 18446744073709551615 18446744073709551615
10000000000000000 18446744073709551615 18446744073709551615 18446744073709551615
1000000000000000 18446744073709551615 18446744073709551615
100000000000000 18446744073709551615 18446744073709551615
10000000000000 18446744073709551615 18446744073709551615 18446744073709551615
1000000000000 18446744073709551615 18446744073709551615
100000000000 18446744073709551615 18446744073709551615
10000000000 18446744073709551615 18446744073709551615 18446744073709551615
1000000000 18446744073709551615 18446744073709551615
100000000 18446744073709551615 18446744073709551615
10000000 18446744073709551615 18446744073709551615 18446744073709551615
1000000 18446744073709551615 18446744073709551615
100000 18446744073709551615 18446744073709551615
10000 18446744073709551615 18446744073709551615 18446744073709551615
1000 18446744073709551615 18446744073709551615
100 18446744073709551615 18446744073709551615
10 18446744073709551615 18446744073709551615 18446744073709551615
*/
for i, j := 0, 0; i < factorsCount; i++ {
lookup64[j] = factors[i]
lookup64[j+1] = maxUint64
lookup64[j+2] = maxUint64
j += 3
if i%3 == 0 {
lookup64[j] = maxUint64
j++
}
}
}