3
0
mirror of https://github.com/ergochat/ergo.git synced 2025-02-13 04:00:48 +01:00
ergo/irc/utils/types.go

30 lines
501 B
Go
Raw Normal View History

2020-08-04 21:46:16 -04:00
// Copyright (c) 2020 Shivaram Lingamneni
// released under the MIT license
package utils
type empty struct{}
2022-03-30 00:44:51 -04:00
type HashSet[T comparable] map[T]empty
2020-08-04 21:46:16 -04:00
2022-03-30 00:44:51 -04:00
func (s HashSet[T]) Has(elem T) bool {
_, ok := s[elem]
2020-08-04 21:46:16 -04:00
return ok
}
2022-03-30 00:44:51 -04:00
func (s HashSet[T]) Add(elem T) {
s[elem] = empty{}
}
func (s HashSet[T]) Remove(elem T) {
delete(s, elem)
}
2023-06-01 06:28:02 -04:00
func SetLiteral[T comparable](elems ...T) HashSet[T] {
result := make(HashSet[T], len(elems))
for _, elem := range elems {
result.Add(elem)
}
return result
}