grype/internal/stringutil/stringset.go

39 lines
579 B
Go
Raw Normal View History

package stringutil
2020-06-19 14:12:29 +00:00
type StringSet map[string]struct{}
2020-06-19 14:12:29 +00:00
func NewStringSet() StringSet {
return make(StringSet)
}
func NewStringSetFromSlice(start []string) StringSet {
ret := make(StringSet)
for _, s := range start {
ret.Add(s)
}
return ret
}
2020-06-19 14:12:29 +00:00
func (s StringSet) Add(i string) {
s[i] = struct{}{}
}
2020-06-19 14:12:29 +00:00
func (s StringSet) Remove(i string) {
delete(s, i)
}
2020-06-19 14:12:29 +00:00
func (s StringSet) Contains(i string) bool {
_, ok := s[i]
return ok
}
2020-07-15 11:17:21 +00:00
func (s StringSet) ToSlice() []string {
ret := make([]string, len(s))
idx := 0
for v := range s {
ret[idx] = v
idx++
}
return ret
}