-
Notifications
You must be signed in to change notification settings - Fork 1
/
conditions.go
201 lines (195 loc) · 2.79 KB
/
conditions.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
package main
func leadingZeroBits(c uint) func([]byte) bool {
cd8,emcm8:=c>>3,8-c%8
if emcm8 == 8 {
return leadingZeroBytes(cd8)
}
return func(t []byte) bool {
return leadingZeroBytes(cd8)(t) && t[cd8]>>emcm8 == 0
}
}
func leadingZeroBytes(c uint) func([]byte) bool {
return func(t []byte) bool {
switch c {
case 16:
if t[15] != 0 {
return false
}
fallthrough
case 15:
if t[14] != 0 {
return false
}
fallthrough
case 14:
if t[13] != 0 {
return false
}
fallthrough
case 13:
if t[12] != 0 {
return false
}
fallthrough
case 12:
if t[11] != 0 {
return false
}
fallthrough
case 11:
if t[10] != 0 {
return false
}
fallthrough
case 10:
if t[9] != 0 {
return false
}
fallthrough
case 9:
if t[8] != 0 {
return false
}
fallthrough
case 8:
if t[7] != 0 {
return false
}
fallthrough
case 7:
if t[6] != 0 {
return false
}
fallthrough
case 6:
if t[5] != 0 {
return false
}
fallthrough
case 5:
if t[4] != 0 {
return false
}
fallthrough
case 4:
if t[3] != 0 {
return false
}
fallthrough
case 3:
if t[2] != 0 {
return false
}
fallthrough
case 2:
if t[1] != 0 {
return false
}
fallthrough
case 1:
if t[0] != 0 {
return false
}
fallthrough
default:
return true
}
}
}
func leadingSetBits(c uint) func([]byte) bool {
cd8,emcm8:=c>>3,8-c%8
if emcm8 == 8 {
return leadingSetBytes(cd8)
}
return func(t []byte) bool {
return leadingSetBytes(cd8)(t) && ^t[cd8]>>emcm8 ==0
}
}
func leadingSetBytes(c uint) func([]byte) bool {
return func(t []byte) bool {
switch c {
case 16:
if t[15] != 0xff {
return false
}
fallthrough
case 15:
if t[14] != 0xff {
return false
}
fallthrough
case 14:
if t[13] != 0xff {
return false
}
fallthrough
case 13:
if t[12] != 0xff {
return false
}
fallthrough
case 12:
if t[11] != 0xff {
return false
}
fallthrough
case 11:
if t[10] != 0xff {
return false
}
fallthrough
case 10:
if t[9] != 0xff {
return false
}
fallthrough
case 9:
if t[8] != 0xff {
return false
}
fallthrough
case 8:
if t[7] != 0xff {
return false
}
fallthrough
case 7:
if t[6] != 0xff {
return false
}
fallthrough
case 6:
if t[5] != 0xff {
return false
}
fallthrough
case 5:
if t[4] != 0xff {
return false
}
fallthrough
case 4:
if t[3] != 0xff {
return false
}
fallthrough
case 3:
if t[2] != 0xff {
return false
}
fallthrough
case 2:
if t[1] != 0xff {
return false
}
fallthrough
case 1:
if t[0] != 0xff {
return false
}
fallthrough
default:
return true
}
}
}