forked from constabulary/gb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringset.go
52 lines (48 loc) · 901 Bytes
/
stringset.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
package vendor
// union returns the union of a and b.
func union(a, b map[string]bool) map[string]bool {
r := make(map[string]bool)
for k := range a {
r[k] = true
}
for k := range b {
r[k] = true
}
return r
}
// intersection returns the intersection of a and b.
func intersection(a, b map[string]bool) map[string]bool {
r := make(map[string]bool)
for k := range a {
if b[k] {
r[k] = true
}
}
return r
}
// difference returns the symetric difference of a and b.
func difference(a, b map[string]bool) map[string]bool {
r := make(map[string]bool)
for k := range a {
if !b[k] {
r[k] = true
}
}
for k := range b {
if !a[k] {
r[k] = true
}
}
return r
}
// contains returns true if a contains all the elements in s.
func contains(a map[string]bool, s ...string) bool {
var r bool
for _, e := range s {
if !a[e] {
return false
}
r = true
}
return r
}