-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
int.go
568 lines (512 loc) · 16.7 KB
/
int.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
package encoding
import (
"encoding/binary"
"fmt"
"sync"
)
// MarshalUint16 appends marshaled v to dst and returns the result.
func MarshalUint16(dst []byte, u uint16) []byte {
return append(dst, byte(u>>8), byte(u))
}
// UnmarshalUint16 returns unmarshaled uint16 from src.
//
// the caller must ensure that len(src) >= 2
func UnmarshalUint16(src []byte) uint16 {
// This is faster than the manual conversion.
return binary.BigEndian.Uint16(src)
}
// MarshalUint32 appends marshaled v to dst and returns the result.
func MarshalUint32(dst []byte, u uint32) []byte {
return append(dst, byte(u>>24), byte(u>>16), byte(u>>8), byte(u))
}
// UnmarshalUint32 returns unmarshaled uint32 from src.
//
// The caller must ensure than len(src) >= 4
func UnmarshalUint32(src []byte) uint32 {
// This is faster than the manual conversion.
return binary.BigEndian.Uint32(src)
}
// MarshalUint64 appends marshaled v to dst and returns the result.
func MarshalUint64(dst []byte, u uint64) []byte {
return append(dst, byte(u>>56), byte(u>>48), byte(u>>40), byte(u>>32), byte(u>>24), byte(u>>16), byte(u>>8), byte(u))
}
// UnmarshalUint64 returns unmarshaled uint64 from src.
//
// The caller must ensure that len(src) >= 8
func UnmarshalUint64(src []byte) uint64 {
// This is faster than the manual conversion.
return binary.BigEndian.Uint64(src)
}
// MarshalInt16 appends marshaled v to dst and returns the result.
func MarshalInt16(dst []byte, v int16) []byte {
// Such encoding for negative v must improve compression.
v = (v << 1) ^ (v >> 15) // zig-zag encoding without branching.
u := uint16(v)
return append(dst, byte(u>>8), byte(u))
}
// UnmarshalInt16 returns unmarshaled int16 from src.
//
// The caller must ensure that len(src) >= 2
func UnmarshalInt16(src []byte) int16 {
// This is faster than the manual conversion.
u := binary.BigEndian.Uint16(src)
v := int16(u>>1) ^ (int16(u<<15) >> 15) // zig-zag decoding without branching.
return v
}
// MarshalInt64 appends marshaled v to dst and returns the result.
func MarshalInt64(dst []byte, v int64) []byte {
// Such encoding for negative v must improve compression.
v = (v << 1) ^ (v >> 63) // zig-zag encoding without branching.
u := uint64(v)
return append(dst, byte(u>>56), byte(u>>48), byte(u>>40), byte(u>>32), byte(u>>24), byte(u>>16), byte(u>>8), byte(u))
}
// UnmarshalInt64 returns unmarshaled int64 from src.
//
// The caller must ensure that len(src) >= 8
func UnmarshalInt64(src []byte) int64 {
// This is faster than the manual conversion.
u := binary.BigEndian.Uint64(src)
v := int64(u>>1) ^ (int64(u<<63) >> 63) // zig-zag decoding without branching.
return v
}
// MarshalVarInt64 appends marshalsed v to dst and returns the result.
func MarshalVarInt64(dst []byte, v int64) []byte {
var tmp [1]int64
tmp[0] = v
return MarshalVarInt64s(dst, tmp[:])
}
// MarshalVarInt64s appends marshaled vs to dst and returns the result.
func MarshalVarInt64s(dst []byte, vs []int64) []byte {
dstLen := len(dst)
for _, v := range vs {
if v >= (1<<6) || v <= (-1<<6) {
return marshalVarInt64sSlow(dst[:dstLen], vs)
}
u := uint64((v << 1) ^ (v >> 63))
dst = append(dst, byte(u))
}
return dst
}
func marshalVarInt64sSlow(dst []byte, vs []int64) []byte {
for _, v := range vs {
u := uint64((v << 1) ^ (v >> 63))
// Cases below are sorted in the descending order of frequency on real data
if u < (1 << 7) {
dst = append(dst, byte(u))
continue
}
if u < (1 << (2 * 7)) {
dst = append(dst, byte(u|0x80), byte(u>>7))
continue
}
if u < (1 << (3 * 7)) {
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte(u>>(2*7)))
continue
}
if u >= (1 << (8 * 7)) {
if u < (1 << (9 * 7)) {
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte((u>>(2*7))|0x80), byte((u>>(3*7))|0x80), byte((u>>(4*7))|0x80),
byte((u>>(5*7))|0x80), byte((u>>(6*7))|0x80), byte((u>>(7*7))|0x80), byte(u>>(8*7)))
continue
}
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte((u>>(2*7))|0x80), byte((u>>(3*7))|0x80), byte((u>>(4*7))|0x80),
byte((u>>(5*7))|0x80), byte((u>>(6*7))|0x80), byte((u>>(7*7))|0x80), byte((u>>(8*7))|0x80), 1)
continue
}
if u < (1 << (4 * 7)) {
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte((u>>(2*7))|0x80), byte(u>>(3*7)))
continue
}
if u < (1 << (5 * 7)) {
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte((u>>(2*7))|0x80), byte((u>>(3*7))|0x80), byte(u>>(4*7)))
continue
}
if u < (1 << (6 * 7)) {
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte((u>>(2*7))|0x80), byte((u>>(3*7))|0x80), byte((u>>(4*7))|0x80), byte(u>>(5*7)))
continue
}
if u < (1 << (7 * 7)) {
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte((u>>(2*7))|0x80), byte((u>>(3*7))|0x80), byte((u>>(4*7))|0x80), byte((u>>(5*7))|0x80), byte(u>>(6*7)))
continue
}
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte((u>>(2*7))|0x80), byte((u>>(3*7))|0x80), byte((u>>(4*7))|0x80),
byte((u>>(5*7))|0x80), byte((u>>(6*7))|0x80), byte(u>>(7*7)))
}
return dst
}
// UnmarshalVarInt64 returns unmarshaled int64 from src and returns
// the remaining tail from src.
func UnmarshalVarInt64(src []byte) ([]byte, int64, error) {
var tmp [1]int64
tail, err := UnmarshalVarInt64s(tmp[:], src)
return tail, tmp[0], err
}
// UnmarshalVarInt64s unmarshals len(dst) int64 values from src to dst
// and returns the remaining tail from src.
func UnmarshalVarInt64s(dst []int64, src []byte) ([]byte, error) {
if len(src) < len(dst) {
return src, fmt.Errorf("too small len(src)=%d; it must be bigger or equal to len(dst)=%d", len(src), len(dst))
}
for i := range dst {
c := src[i]
if c >= 0x80 {
return unmarshalVarInt64sSlow(dst, src)
}
dst[i] = int64(int8(c>>1) ^ (int8(c<<7) >> 7))
}
return src[len(dst):], nil
}
func unmarshalVarInt64sSlow(dst []int64, src []byte) ([]byte, error) {
idx := uint(0)
for i := range dst {
if idx >= uint(len(src)) {
return nil, fmt.Errorf("cannot unmarshal varint from empty data")
}
c := src[idx]
idx++
if c < 0x80 {
// Fast path for 1 byte
dst[i] = int64(int8(c>>1) ^ (int8(c<<7) >> 7))
continue
}
if idx >= uint(len(src)) {
return nil, fmt.Errorf("unexpected end of encoded varint at byte 1; src=%x", src[idx-1:])
}
d := src[idx]
idx++
if d < 0x80 {
// Fast path for 2 bytes
u := uint64(c&0x7f) | (uint64(d) << 7)
dst[i] = int64(u>>1) ^ (int64(u<<63) >> 63)
continue
}
if idx >= uint(len(src)) {
return nil, fmt.Errorf("unexpected end of encoded varint at byte 2; src=%x", src[idx-2:])
}
e := src[idx]
idx++
if e < 0x80 {
// Fast path for 3 bytes
u := uint64(c&0x7f) | (uint64(d&0x7f) << 7) | (uint64(e) << (2 * 7))
dst[i] = int64(u>>1) ^ (int64(u<<63) >> 63)
continue
}
u := uint64(c&0x7f) | (uint64(d&0x7f) << 7) | (uint64(e&0x7f) << (2 * 7))
// Slow path
j := idx
for {
if idx >= uint(len(src)) {
return nil, fmt.Errorf("unexpected end of encoded varint; src=%x", src[j-3:])
}
c := src[idx]
idx++
if c < 0x80 {
break
}
}
// These are the most common cases
switch idx - j {
case 1:
u |= (uint64(src[j]) << (3 * 7))
case 2:
b := src[j : j+2 : j+2]
u |= (uint64(b[0]&0x7f) << (3 * 7)) | (uint64(b[1]) << (4 * 7))
case 3:
b := src[j : j+3 : j+3]
u |= (uint64(b[0]&0x7f) << (3 * 7)) | (uint64(b[1]&0x7f) << (4 * 7)) | (uint64(b[2]) << (5 * 7))
case 4:
b := src[j : j+4 : j+4]
u |= (uint64(b[0]&0x7f) << (3 * 7)) | (uint64(b[1]&0x7f) << (4 * 7)) | (uint64(b[2]&0x7f) << (5 * 7)) | (uint64(b[3]) << (6 * 7))
case 5:
b := src[j : j+5 : j+5]
u |= (uint64(b[0]&0x7f) << (3 * 7)) | (uint64(b[1]&0x7f) << (4 * 7)) | (uint64(b[2]&0x7f) << (5 * 7)) | (uint64(b[3]&0x7f) << (6 * 7)) |
(uint64(b[4]) << (7 * 7))
case 6:
b := src[j : j+6 : j+6]
u |= (uint64(b[0]&0x7f) << (3 * 7)) | (uint64(b[1]&0x7f) << (4 * 7)) | (uint64(b[2]&0x7f) << (5 * 7)) | (uint64(b[3]&0x7f) << (6 * 7)) |
(uint64(b[4]&0x7f) << (7 * 7)) | (uint64(b[5]) << (8 * 7))
case 7:
b := src[j : j+7 : j+7]
if b[6] > 1 {
return src[idx:], fmt.Errorf("too big encoded varint; src=%x", src[j-3:])
}
u |= (uint64(b[0]&0x7f) << (3 * 7)) | (uint64(b[1]&0x7f) << (4 * 7)) | (uint64(b[2]&0x7f) << (5 * 7)) | (uint64(b[3]&0x7f) << (6 * 7)) |
(uint64(b[4]&0x7f) << (7 * 7)) | (uint64(b[5]&0x7f) << (8 * 7)) | (1 << (9 * 7))
default:
return src[idx:], fmt.Errorf("too long encoded varint; the maximum allowed length is 10 bytes; got %d bytes; src=%x", idx-j+3, src[j-3:])
}
dst[i] = int64(u>>1) ^ (int64(u<<63) >> 63)
}
return src[idx:], nil
}
// MarshalVarUint64 appends marshaled u to dst and returns the result.
func MarshalVarUint64(dst []byte, u uint64) []byte {
var tmp [1]uint64
tmp[0] = u
return MarshalVarUint64s(dst, tmp[:])
}
// MarshalVarUint64s appends marshaled us to dst and returns the result.
func MarshalVarUint64s(dst []byte, us []uint64) []byte {
dstLen := len(dst)
for _, u := range us {
if u >= (1 << 7) {
return marshalVarUint64sSlow(dst[:dstLen], us)
}
dst = append(dst, byte(u))
}
return dst
}
func marshalVarUint64sSlow(dst []byte, us []uint64) []byte {
for _, u := range us {
// Cases below are sorted in the descending order of frequency on real data
if u < (1 << 7) {
dst = append(dst, byte(u))
continue
}
if u < (1 << (2 * 7)) {
dst = append(dst, byte(u|0x80), byte(u>>7))
continue
}
if u < (1 << (3 * 7)) {
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte(u>>(2*7)))
continue
}
if u >= (1 << (8 * 7)) {
if u < (1 << (9 * 7)) {
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte((u>>(2*7))|0x80), byte((u>>(3*7))|0x80), byte((u>>(4*7))|0x80),
byte((u>>(5*7))|0x80), byte((u>>(6*7))|0x80), byte((u>>(7*7))|0x80), byte(u>>(8*7)))
continue
}
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte((u>>(2*7))|0x80), byte((u>>(3*7))|0x80), byte((u>>(4*7))|0x80),
byte((u>>(5*7))|0x80), byte((u>>(6*7))|0x80), byte((u>>(7*7))|0x80), byte((u>>(8*7))|0x80), 1)
continue
}
if u < (1 << (4 * 7)) {
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte((u>>(2*7))|0x80), byte(u>>(3*7)))
continue
}
if u < (1 << (5 * 7)) {
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte((u>>(2*7))|0x80), byte((u>>(3*7))|0x80), byte(u>>(4*7)))
continue
}
if u < (1 << (6 * 7)) {
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte((u>>(2*7))|0x80), byte((u>>(3*7))|0x80), byte((u>>(4*7))|0x80), byte(u>>(5*7)))
continue
}
if u < (1 << (7 * 7)) {
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte((u>>(2*7))|0x80), byte((u>>(3*7))|0x80), byte((u>>(4*7))|0x80), byte((u>>(5*7))|0x80), byte(u>>(6*7)))
continue
}
dst = append(dst, byte(u|0x80), byte((u>>7)|0x80), byte((u>>(2*7))|0x80), byte((u>>(3*7))|0x80), byte((u>>(4*7))|0x80),
byte((u>>(5*7))|0x80), byte((u>>(6*7))|0x80), byte(u>>(7*7)))
}
return dst
}
// UnmarshalVarUint64 returns unmarshaled uint64 from src and returns
// the remaining tail from src.
func UnmarshalVarUint64(src []byte) ([]byte, uint64, error) {
var tmp [1]uint64
tail, err := UnmarshalVarUint64s(tmp[:], src)
return tail, tmp[0], err
}
// UnmarshalVarUint64s unmarshals len(dst) uint64 values from src to dst
// and returns the remaining tail from src.
func UnmarshalVarUint64s(dst []uint64, src []byte) ([]byte, error) {
if len(src) < len(dst) {
return src, fmt.Errorf("too small len(src)=%d; it must be bigger or equal to len(dst)=%d", len(src), len(dst))
}
for i := range dst {
c := src[i]
if c >= 0x80 {
return unmarshalVarUint64sSlow(dst, src)
}
dst[i] = uint64(c)
}
return src[len(dst):], nil
}
func unmarshalVarUint64sSlow(dst []uint64, src []byte) ([]byte, error) {
idx := uint(0)
for i := range dst {
if idx >= uint(len(src)) {
return nil, fmt.Errorf("cannot unmarshal varuint from empty data")
}
c := src[idx]
idx++
if c < 0x80 {
// Fast path for 1 byte
dst[i] = uint64(c)
continue
}
if idx >= uint(len(src)) {
return nil, fmt.Errorf("unexpected end of encoded varuint at byte 1; src=%x", src[idx-1:])
}
d := src[idx]
idx++
if d < 0x80 {
// Fast path for 2 bytes
dst[i] = uint64(c&0x7f) | (uint64(d) << 7)
continue
}
if idx >= uint(len(src)) {
return nil, fmt.Errorf("unexpected end of encoded varuint at byte 2; src=%x", src[idx-2:])
}
e := src[idx]
idx++
if e < 0x80 {
// Fast path for 3 bytes
dst[i] = uint64(c&0x7f) | (uint64(d&0x7f) << 7) | (uint64(e) << (2 * 7))
continue
}
u := uint64(c&0x7f) | (uint64(d&0x7f) << 7) | (uint64(e&0x7f) << (2 * 7))
// Slow path
j := idx
for {
if idx >= uint(len(src)) {
return nil, fmt.Errorf("unexpected end of encoded varint; src=%x", src[j-3:])
}
c := src[idx]
idx++
if c < 0x80 {
break
}
}
// These are the most common cases
switch idx - j {
case 1:
u |= (uint64(src[j]) << (3 * 7))
case 2:
b := src[j : j+2 : j+2]
u |= (uint64(b[0]&0x7f) << (3 * 7)) | (uint64(b[1]) << (4 * 7))
case 3:
b := src[j : j+3 : j+3]
u |= (uint64(b[0]&0x7f) << (3 * 7)) | (uint64(b[1]&0x7f) << (4 * 7)) | (uint64(b[2]) << (5 * 7))
case 4:
b := src[j : j+4 : j+4]
u |= (uint64(b[0]&0x7f) << (3 * 7)) | (uint64(b[1]&0x7f) << (4 * 7)) | (uint64(b[2]&0x7f) << (5 * 7)) | (uint64(b[3]) << (6 * 7))
case 5:
b := src[j : j+5 : j+5]
u |= (uint64(b[0]&0x7f) << (3 * 7)) | (uint64(b[1]&0x7f) << (4 * 7)) | (uint64(b[2]&0x7f) << (5 * 7)) | (uint64(b[3]&0x7f) << (6 * 7)) |
(uint64(b[4]) << (7 * 7))
case 6:
b := src[j : j+6 : j+6]
u |= (uint64(b[0]&0x7f) << (3 * 7)) | (uint64(b[1]&0x7f) << (4 * 7)) | (uint64(b[2]&0x7f) << (5 * 7)) | (uint64(b[3]&0x7f) << (6 * 7)) |
(uint64(b[4]&0x7f) << (7 * 7)) | (uint64(b[5]) << (8 * 7))
case 7:
b := src[j : j+7 : j+7]
if b[6] > 1 {
return src[idx:], fmt.Errorf("too big encoded varuint; src=%x", src[j-3:])
}
u |= (uint64(b[0]&0x7f) << (3 * 7)) | (uint64(b[1]&0x7f) << (4 * 7)) | (uint64(b[2]&0x7f) << (5 * 7)) | (uint64(b[3]&0x7f) << (6 * 7)) |
(uint64(b[4]&0x7f) << (7 * 7)) | (uint64(b[5]&0x7f) << (8 * 7)) | (1 << (9 * 7))
default:
return src[idx:], fmt.Errorf("too long encoded varuint; the maximum allowed length is 10 bytes; got %d bytes; src=%x", idx-j+3, src[j-3:])
}
dst[i] = u
}
return src[idx:], nil
}
// MarshalBool appends marshaled v to dst and returns the result.
func MarshalBool(dst []byte, v bool) []byte {
x := byte(0)
if v {
x = 1
}
return append(dst, x)
}
// UnmarshalBool unmarshals bool from src.
func UnmarshalBool(src []byte) bool {
return src[0] != 0
}
// MarshalBytes appends marshaled b to dst and returns the result.
func MarshalBytes(dst, b []byte) []byte {
dst = MarshalVarUint64(dst, uint64(len(b)))
dst = append(dst, b...)
return dst
}
// UnmarshalBytes returns unmarshaled bytes from src.
func UnmarshalBytes(src []byte) ([]byte, []byte, error) {
tail, n, err := UnmarshalVarUint64(src)
if err != nil {
return nil, nil, fmt.Errorf("cannot unmarshal string size: %w", err)
}
src = tail
if uint64(len(src)) < n {
return nil, nil, fmt.Errorf("src is too short for reading string with size %d; len(src)=%d", n, len(src))
}
return src[n:], src[:n], nil
}
// GetInt64s returns an int64 slice with the given size.
// The slice contents isn't initialized - it may contain garbage.
func GetInt64s(size int) *Int64s {
v := int64sPool.Get()
if v == nil {
return &Int64s{
A: make([]int64, size),
}
}
is := v.(*Int64s)
if n := size - cap(is.A); n > 0 {
is.A = append(is.A[:cap(is.A)], make([]int64, n)...)
}
is.A = is.A[:size]
return is
}
// PutInt64s returns is to the pool.
func PutInt64s(is *Int64s) {
int64sPool.Put(is)
}
// Int64s holds an int64 slice
type Int64s struct {
A []int64
}
var int64sPool sync.Pool
// GetUint64s returns an uint64 slice with the given size.
// The slice contents isn't initialized - it may contain garbage.
func GetUint64s(size int) *Uint64s {
v := uint64sPool.Get()
if v == nil {
return &Uint64s{
A: make([]uint64, size),
}
}
is := v.(*Uint64s)
if n := size - cap(is.A); n > 0 {
is.A = append(is.A[:cap(is.A)], make([]uint64, n)...)
}
is.A = is.A[:size]
return is
}
// PutUint64s returns is to the pool.
func PutUint64s(is *Uint64s) {
uint64sPool.Put(is)
}
// Uint64s holds an uint64 slice
type Uint64s struct {
A []uint64
}
var uint64sPool sync.Pool
// GetUint32s returns an uint32 slice with the given size.
// The slize contents isn't initialized - it may contain garbage.
func GetUint32s(size int) *Uint32s {
v := uint32sPool.Get()
if v == nil {
return &Uint32s{
A: make([]uint32, size),
}
}
is := v.(*Uint32s)
if n := size - cap(is.A); n > 0 {
is.A = append(is.A[:cap(is.A)], make([]uint32, n)...)
}
is.A = is.A[:size]
return is
}
// PutUint32s returns is to the pool.
func PutUint32s(is *Uint32s) {
uint32sPool.Put(is)
}
// Uint32s holds an uint32 slice
type Uint32s struct {
A []uint32
}
var uint32sPool sync.Pool