Set should have a difference function

This commit is contained in:
derekwaynecarr
2015-02-13 13:28:34 -05:00
parent 485cb0b2f9
commit e7a0340ad7
2 changed files with 35 additions and 0 deletions

View File

@@ -62,6 +62,22 @@ func (s StringSet) HasAll(items ...string) bool {
return true
}
// Difference returns a set of objects that are not in s2
// For example:
// s1 = {1, 2, 3}
// s2 = {1, 2, 4, 5}
// s1.Difference(s2) = {3}
// s2.Difference(s1) = {4, 5}
func (s StringSet) Difference(s2 StringSet) StringSet {
result := NewStringSet()
for key := range s {
if !s2.Has(key) {
result.Insert(key)
}
}
return result
}
// IsSuperset returns true iff s1 is a superset of s2.
func (s1 StringSet) IsSuperset(s2 StringSet) bool {
for item := range s2 {