2020-08-05 03:46:16 +02:00
|
|
|
// Copyright (c) 2020 Shivaram Lingamneni
|
|
|
|
// released under the MIT license
|
|
|
|
|
|
|
|
package utils
|
|
|
|
|
|
|
|
type empty struct{}
|
|
|
|
|
|
|
|
type StringSet map[string]empty
|
|
|
|
|
|
|
|
func (s StringSet) Has(str string) bool {
|
|
|
|
_, ok := s[str]
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s StringSet) Add(str string) {
|
|
|
|
s[str] = empty{}
|
|
|
|
}
|
2021-09-12 22:51:43 +02:00
|
|
|
|
|
|
|
func (s StringSet) Remove(str string) {
|
|
|
|
_, ok := s[str]
|
|
|
|
if ok {
|
|
|
|
delete(s, str)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s StringSet) Size() int {
|
|
|
|
return len(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s StringSet) Keys() (keys []string) {
|
|
|
|
for key := range s {
|
|
|
|
keys = append(keys, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
return keys
|
|
|
|
}
|