mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-29 09:15:33 +00:00
Initiatlize the map right
This commit is contained in:
@@ -2,7 +2,7 @@ package datatypes
|
||||
|
||||
// INFO: use this if your key is unique
|
||||
func MakeMap[T any, U comparable](data []T, f func(T) U) map[U]T {
|
||||
m := make(map[U]T)
|
||||
m := make(map[U]T, len(data))
|
||||
for _, v := range data {
|
||||
m[f(v)] = v
|
||||
}
|
||||
@@ -11,7 +11,7 @@ func MakeMap[T any, U comparable](data []T, f func(T) U) map[U]T {
|
||||
|
||||
// INFO: use this if your key is not unique
|
||||
func MakeMultiMap[T any, U comparable](data []T, f func(T) U) map[U][]T {
|
||||
m := make(map[U][]T)
|
||||
m := make(map[U][]T, len(data))
|
||||
for _, v := range data {
|
||||
m[f(v)] = append(m[f(v)], v)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user