Add a NewStringSet() function

Also beef up tests to cover len(ss).
This commit is contained in:
Tim Hockin
2014-06-28 19:36:44 -07:00
parent 73a494c928
commit b65d685a39
2 changed files with 23 additions and 0 deletions

View File

@@ -21,6 +21,13 @@ type empty struct{}
// A set of strings, implemented via map[string]struct{} for minimal memory consumption.
type StringSet map[string]empty
// NewStringSet creates a StringSet from a list of values.
func NewStringSet(items ...string) StringSet {
ss := StringSet{}
ss.Insert(items...)
return ss
}
// Insert adds items to the set.
func (s StringSet) Insert(items ...string) {
for _, item := range items {