-
Notifications
You must be signed in to change notification settings - Fork 6
/
boolean.go
74 lines (64 loc) · 1013 Bytes
/
boolean.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
package functions
import "golang.org/x/exp/constraints"
func Not_Go(x []bool) {
for i := 0; i < len(x); i++ {
x[i] = !x[i]
}
}
func And_Go(x, y []bool) {
for i := 0; i < len(x); i++ {
x[i] = x[i] && y[i]
}
}
func Or_Go(x, y []bool) {
for i := 0; i < len(x); i++ {
x[i] = x[i] || y[i]
}
}
func Xor_Go(x, y []bool) {
for i := 0; i < len(x); i++ {
x[i] = x[i] != y[i]
}
}
func Select_Go[T constraints.Float](dst, x []T, y []bool) []T {
dst = dst[:0]
for i := 0; i < len(y); i++ {
if y[i] {
dst = append(dst, x[i])
}
}
return dst
}
func All_Go(x []bool) bool {
for i := 0; i < len(x); i++ {
if !x[i] {
return false
}
}
return true
}
func Any_Go(x []bool) bool {
for i := 0; i < len(x); i++ {
if x[i] {
return true
}
}
return false
}
func None_Go(x []bool) bool {
for i := 0; i < len(x); i++ {
if x[i] {
return false
}
}
return true
}
func Count_Go(x []bool) int {
cnt := 0
for i := 0; i < len(x); i++ {
if x[i] {
cnt += 1
}
}
return cnt
}