You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
420 B
25 lines
420 B
package gentools
|
|
|
|
func CopyMap[K comparable, V any](m map[K]V) map[K]V {
|
|
m2 := make(map[K]V, len(m)+1)
|
|
for k, v := range m {
|
|
m2[k] = v
|
|
}
|
|
|
|
return m2
|
|
}
|
|
|
|
func OneItemMap[K comparable, V any](key K, value V) map[K]V {
|
|
m := make(map[K]V, 1)
|
|
m[key] = value
|
|
return m
|
|
}
|
|
|
|
func MapKeys[K comparable, V any](m map[K]V) []K {
|
|
keys := make([]K, 0, len(m))
|
|
for key := range m {
|
|
keys = append(keys, key)
|
|
}
|
|
|
|
return keys
|
|
}
|