3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-28 06:49:24 +01:00
ergo/irc/utils/stringset.go

38 lines
562 B
Go
Raw Normal View History

2020-08-05 03:46:16 +02:00
// Copyright (c) 2020 Shivaram Lingamneni
// Copyright (c) 2021 Daniel Oaks
2020-08-05 03:46:16 +02:00
// 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{}
}
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
}