/
arrays.go
40 lines (36 loc) · 957 Bytes
/
arrays.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
package util
// RemoveFromUint64ArrayStable removes the first occurrence of `match` in the given `array`.
// It returns True if one element was removed. False otherwise.
// The order of the remaining elements is not changed.
func RemoveFromUint64ArrayStable(array []uint64, match uint64) ([]uint64, bool) {
for i, other := range array {
if other == match {
return append(array[0:i], array[i+1:]...), true
}
}
return array, false
}
func RemoveFromStringArrayStable(array []string, match string) ([]string, bool) {
for i, other := range array {
if other == match {
return append(array[0:i], array[i+1:]...), true
}
}
return array, false
}
func ContainsUint64(array []uint64, match uint64) bool {
for _, other := range array {
if other == match {
return true
}
}
return false
}
func ContainsString(array []string, match string) bool {
for _, other := range array {
if other == match {
return true
}
}
return false
}