Merge pull request #122026 from skitt/sets-go1.21

Use Go 1.21 Ordered and clear for sets
This commit is contained in:
Kubernetes Prow Robot 2024-04-29 12:51:18 -07:00 committed by GitHub
commit 84ac8a1bd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -68,14 +68,8 @@ func (s Set[T]) Delete(items ...T) Set[T] {
// Clear empties the set.
// It is preferable to replace the set with a newly constructed set,
// but not all callers can do that (when there are other references to the map).
// In some cases the set *won't* be fully cleared, e.g. a Set[float32] containing NaN
// can't be cleared because NaN can't be removed.
// For sets containing items of a type that is reflexive for ==,
// this is optimized to a single call to runtime.mapclear().
func (s Set[T]) Clear() Set[T] {
for key := range s {
delete(s, key)
}
clear(s)
return s
}