@@ -84,9 +84,7 @@ struct binary {
84
84
#if RUNAWARE
85
85
assert (r > 0 );
86
86
#else
87
- if (!r) {
88
- return ;
89
- }
87
+ if (!r) return ;
90
88
#endif
91
89
assert (x <= r);
92
90
uint32_t b = msb (r) + 1 ;
@@ -118,14 +116,11 @@ struct leftmost_minimal {
118
116
#if RUNAWARE
119
117
assert (r > 0 );
120
118
#else
121
- if (!r) {
122
- return ;
123
- }
119
+ if (!r) return ;
124
120
#endif
125
121
assert (x <= r);
126
- uint32_t n = r + 1 ;
127
- uint32_t b = msb (n);
128
- uint32_t hi = (uint64_t (1 ) << (b + 1 )) - n;
122
+ uint32_t b = msb (r);
123
+ uint32_t hi = (uint64_t (1 ) << (b + 1 )) - r - 1 ;
129
124
if (x < hi) {
130
125
append (x, b);
131
126
} else {
@@ -146,13 +141,10 @@ struct leftmost_minimal {
146
141
#else
147
142
if (!r) return 0 ;
148
143
#endif
149
- uint32_t n = r + 1 ;
150
- uint32_t b = msb (n);
151
- uint32_t hi = (uint64_t (1 ) << (b + 1 )) - n;
144
+ uint32_t b = msb (r);
145
+ uint32_t hi = (uint64_t (1 ) << (b + 1 )) - r - 1 ;
152
146
uint32_t x = take (b);
153
- if (x >= hi) {
154
- x = (x << 1 ) + take (1 ) - hi;
155
- }
147
+ if (x >= hi) x = (x << 1 ) + take (1 ) - hi;
156
148
assert (x <= r);
157
149
return x;
158
150
}
@@ -165,23 +157,16 @@ struct centered_minimal {
165
157
#if RUNAWARE
166
158
assert (r > 0 );
167
159
#else
168
- if (!r) {
169
- return ;
170
- }
160
+ if (!r) return ;
171
161
#endif
172
- uint32_t n = r + 1 ;
173
- uint32_t b = msb (n);
174
- uint32_t c = (uint64_t (1 ) << (b + 1 )) - n;
175
-
162
+ uint32_t b = msb (r);
163
+ uint32_t c = (uint64_t (1 ) << (b + 1 )) - r - 1 ;
176
164
int64_t half_c = c / 2 ;
177
165
int64_t half_r = r / 2 ;
178
166
int64_t lo, hi;
179
167
lo = half_r - half_c;
180
168
hi = half_r + half_c + 1 ;
181
- if (n % 2 ) {
182
- lo -= 1 ;
183
- }
184
-
169
+ if (r % 2 == 0 ) lo -= 1 ;
185
170
if (x > lo and x < hi) {
186
171
append (x, b);
187
172
} else {
@@ -200,23 +185,15 @@ struct centered_minimal {
200
185
#else
201
186
if (!r) return 0 ;
202
187
#endif
203
- uint32_t n = r + 1 ;
204
- uint32_t b = msb (n);
205
- uint32_t c = (uint64_t (1 ) << (b + 1 )) - n;
206
-
188
+ uint32_t b = msb (r);
189
+ uint32_t c = (uint64_t (1 ) << (b + 1 )) - r - 1 ;
207
190
int64_t half_c = c / 2 ;
208
191
int64_t half_r = r / 2 ;
209
- int64_t lo, hi ;
192
+ int64_t lo;
210
193
lo = half_r - half_c;
211
- hi = half_r + half_c + 1 ;
212
- if (n % 2 ) {
213
- lo -= 1 ;
214
- }
215
-
194
+ if (r % 2 == 0 ) lo -= 1 ;
216
195
uint32_t x = take (b);
217
- if (x <= lo or x >= hi) {
218
- x += take (1 ) << b;
219
- }
196
+ if (x <= lo) x += take (1 ) << b;
220
197
assert (x <= r);
221
198
return x;
222
199
}
@@ -249,9 +226,7 @@ struct encoder {
249
226
void encode (uint32_t const * input, uint32_t n, uint32_t lo, uint32_t hi) {
250
227
if (!n) return ;
251
228
#if RUNAWARE
252
- if (hi - lo + 1 == n) { // run
253
- return ;
254
- }
229
+ if (hi - lo + 1 == n) return ; // run
255
230
#endif
256
231
assert (lo <= hi);
257
232
assert (hi - lo >= n - 1 );
@@ -297,9 +272,7 @@ struct decoder {
297
272
assert (lo <= hi);
298
273
#if RUNAWARE
299
274
if (hi - lo + 1 == n) { // run
300
- for (uint32_t i = 0 ; i != n; ++i) {
301
- out[i] = lo + i;
302
- }
275
+ for (uint32_t i = 0 ; i != n; ++i) out[i] = lo++;
303
276
return ;
304
277
}
305
278
#endif
0 commit comments