erigon-pulse/common/sorted.go
Andrew Ashikhmin 424f38a9b6
AuRa: iterate over durations in order (#6013)
Iteration order over go maps is random.
2022-11-10 13:47:57 +01:00

18 lines
262 B
Go

package common
import (
"golang.org/x/exp/constraints"
"golang.org/x/exp/slices"
)
func SortedKeys[K constraints.Ordered, V any](m map[K]V) []K {
keys := make([]K, len(m))
i := 0
for k := range m {
keys[i] = k
i++
}
slices.Sort(keys)
return keys
}