This repository has been archived by the owner on Sep 23, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpopcount_slices_amd64.go
72 lines (58 loc) · 1.9 KB
/
popcount_slices_amd64.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
//
// Package hamming distance calculations in Go
//
// https://github.com/steakknife/hamming
//
// Copyright © 2014, 2015, 2016, 2018 Barry Allard
//
// MIT license
//
package hamming
import (
"strconv"
"unsafe"
)
// CountBitsInt8sPopCnt count 1's in x
func CountBitsInt8sPopCnt(x []int8) (ret int)
// CountBitsInt16sPopCnt count 1's in x
func CountBitsInt16sPopCnt(x []int16) (ret int)
// CountBitsInt32sPopCnt count 1's in x
func CountBitsInt32sPopCnt(x []int32) (ret int)
// CountBitsInt64sPopCnt count 1's in x
func CountBitsInt64sPopCnt(x []int64) (ret int)
// CountBitsIntsPopCnt count 1's in x
func CountBitsIntsPopCnt(x []int) int {
if strconv.IntSize == 64 {
y := (*[]int64)(unsafe.Pointer(&x)) // #nosec G103
return CountBitsInt64sPopCnt(*y)
} else if strconv.IntSize == 32 {
y := (*[]int32)(unsafe.Pointer(&x)) // #nosec G103
return CountBitsInt32sPopCnt(*y)
}
panic("strconv.IntSize must be 32 or 64 bits")
}
// CountBitsUint8sPopCnt count 1's in x
func CountBitsUint8sPopCnt(x []uint8) (ret int)
// CountBitsUint16sPopCnt count 1's in x
func CountBitsUint16sPopCnt(x []uint16) (ret int)
// CountBitsUint32sPopCnt count 1's in x
func CountBitsUint32sPopCnt(x []uint32) (ret int)
// CountBitsUint64sPopCnt count 1's in x
func CountBitsUint64sPopCnt(x []uint64) (ret int)
// CountBitsUintsPopCnt count 1's in x
func CountBitsUintsPopCnt(x []uint) int {
if strconv.IntSize == 64 {
y := (*[]uint64)(unsafe.Pointer(&x)) // #nosec G103
return CountBitsUint64sPopCnt(*y)
} else if strconv.IntSize == 32 {
y := (*[]uint32)(unsafe.Pointer(&x)) // #nosec G103
return CountBitsUint32sPopCnt(*y)
}
panic("strconv.IntSize must be 32 or 64 bits")
}
// CountBitsBytesPopCnt count 1's in x
func CountBitsBytesPopCnt(x []byte) (ret int)
// CountBitsRunesPopCnt count 1's in x
func CountBitsRunesPopCnt(x []rune) (ret int)
// CountBitsStringPopCnt count 1's in s
func CountBitsStringPopCnt(s string) (ret int)