-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcount.go
More file actions
50 lines (47 loc) · 837 Bytes
/
count.go
File metadata and controls
50 lines (47 loc) · 837 Bytes
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
package num
import (
"gitee.com/quant1x/num/x64"
)
// Count 统计
func Count[T Number | ~bool](x []T) int {
switch vs := any(x).(type) {
case []bool:
return x64.Count(vs)
case []int8:
return __count_go(vs)
case []uint8:
return __count_go(vs)
case []int16:
return __count_go(vs)
case []uint16:
return __count_go(vs)
case []int32:
return __count_go(vs)
case []uint32:
return __count_go(vs)
case []int64:
return __count_go(vs)
case []uint64:
return __count_go(vs)
case []int:
return __count_go(vs)
case []uint:
return __count_go(vs)
case []uintptr:
return __count_go(vs)
case []float32:
return __count_go(vs)
case []float64:
return __count_go(vs)
}
return 0
}
func __count_go[T Number](x []T) int {
cnt := 0
for i := 0; i < len(x); i++ {
if x[i] != 0 {
cnt += 1
}
}
return cnt
}