Set the initial length of set[T] in sets.KeySet

Signed-off-by: Iceber Gu <caiwei95@hotmail.com>
This commit is contained in:
Iceber Gu 2023-11-12 00:08:01 +08:00
parent 6b8b188149
commit 33aa56097a

View File

@ -37,7 +37,7 @@ func New[T comparable](items ...T) Set[T] {
// KeySet creates a Set from a keys of a map[comparable](? extends interface{}).
// If the value passed in is not actually a map, this will panic.
func KeySet[T comparable, V any](theMap map[T]V) Set[T] {
ret := Set[T]{}
ret := make(Set[T], len(theMap))
for keyValue := range theMap {
ret.Insert(keyValue)
}