Added HasAll utility method for string set.

Added HasAll method which detects if one set contains all
of the memebers of another set.

A.HasAll(B) returns true if A is a superset of B.
This commit is contained in:
Danny Jones
2014-07-18 13:08:11 -07:00
parent fda69bcca2
commit 2d9bad95f8
3 changed files with 22 additions and 1 deletions

View File

@@ -50,6 +50,16 @@ func (s StringSet) Has(item string) bool {
return contained
}
// HasAll returns true iff all items are contained in the set.
func (s1 StringSet) HasAll(s2 StringSet) bool {
for item, _ := range s2 {
if !s1.Has(item) {
return false
}
}
return true
}
// List returns the contents as a sorted string slice.
func (s StringSet) List() []string {
res := make([]string, 0, len(s))