-
Notifications
You must be signed in to change notification settings - Fork 134
/
list.go
60 lines (54 loc) · 1.04 KB
/
list.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
package util
func SubtractStringList(a []string, b []string) []string {
bSet := StringListToSet(b)
result := []string{}
for _, item := range a {
if !bSet[item] {
result = append(result, item)
}
}
return result
}
func StringListToSet(list []string) map[string]bool {
set := map[string]bool{}
for _, item := range list {
set[item] = true
}
return set
}
func ContainsString(list []string, val string) bool {
for _, elem := range list {
if elem == val {
return true
}
}
return false
}
func DeepCopyListUint32(list []uint32) []uint32 {
result := make([]uint32, 0, len(list))
for _, v := range list {
result = append(result, v)
}
return result
}
func Filter[T any](list []T, predicate func(val T) bool) []T {
var out []T
for _, val := range list {
if predicate(val) {
out = append(out, val)
}
}
return out
}
func Concat[T any](slices ...[]T) []T {
total := 0
for _, s := range slices {
total += len(s)
}
result := make([]T, total)
var i int
for _, s := range slices {
i += copy(result[i:], s)
}
return result
}