github.com/seh/gb@v0.4.4-0.20160724065125-065d2b2b1ba1/cmd/gb/stringset.go (about) 1 package main 2 3 // union returns the union of a and b. 4 func union(a, b map[string]bool) map[string]bool { 5 r := make(map[string]bool) 6 for k := range a { 7 r[k] = true 8 } 9 for k := range b { 10 r[k] = true 11 } 12 return r 13 } 14 15 // intersection returns the intersection of a and b. 16 func intersection(a, b map[string]bool) map[string]bool { 17 r := make(map[string]bool) 18 for k := range a { 19 if b[k] { 20 r[k] = true 21 } 22 } 23 return r 24 } 25 26 // difference returns the symetric difference of a and b. 27 func difference(a, b map[string]bool) map[string]bool { 28 r := make(map[string]bool) 29 for k := range a { 30 if !b[k] { 31 r[k] = true 32 } 33 } 34 for k := range b { 35 if !a[k] { 36 r[k] = true 37 } 38 } 39 return r 40 } 41 42 // contains returns true if a contains all the elements in s. 43 func contains(a map[string]bool, s ...string) bool { 44 var r bool 45 for _, e := range s { 46 if !a[e] { 47 return false 48 } 49 r = true 50 } 51 return r 52 }