forked from External/ergo
upgrade to go 1.18, use generics
This commit is contained in:
parent
446c654dea
commit
a549827f17
15 changed files with 60 additions and 67 deletions
|
|
@ -5,13 +5,25 @@ package utils
|
|||
|
||||
type empty struct{}
|
||||
|
||||
type StringSet map[string]empty
|
||||
type HashSet[T comparable] map[T]empty
|
||||
|
||||
func (s StringSet) Has(str string) bool {
|
||||
_, ok := s[str]
|
||||
func (s HashSet[T]) Has(elem T) bool {
|
||||
_, ok := s[elem]
|
||||
return ok
|
||||
}
|
||||
|
||||
func (s StringSet) Add(str string) {
|
||||
s[str] = empty{}
|
||||
func (s HashSet[T]) Add(elem T) {
|
||||
s[elem] = empty{}
|
||||
}
|
||||
|
||||
func (s HashSet[T]) Remove(elem T) {
|
||||
delete(s, elem)
|
||||
}
|
||||
|
||||
func CopyMap[K comparable, V any](input map[K]V) (result map[K]V) {
|
||||
result = make(map[K]V, len(input))
|
||||
for key, value := range input {
|
||||
result[key] = value
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue