Use common helper functions for getting sorted map keys.

Add a new helper SortedIntKeys similar to SortedStringKeys.

Test: lunch aosp_cf_x86_phone-userdebug && m
Change-Id: I08a43ec2cae7d1a82531295aca1a0658e3a0dd6f
This commit is contained in:
Ulya Trafimovich
2020-08-20 11:33:12 +01:00
parent 9ce2221791
commit b8063c6a86
5 changed files with 17 additions and 24 deletions

View File

@@ -79,6 +79,20 @@ func JoinWithSuffix(strs []string, suffix string, separator string) string {
return string(ret)
}
func SortedIntKeys(m interface{}) []int {
v := reflect.ValueOf(m)
if v.Kind() != reflect.Map {
panic(fmt.Sprintf("%#v is not a map", m))
}
keys := v.MapKeys()
s := make([]int, 0, len(keys))
for _, key := range keys {
s = append(s, int(key.Int()))
}
sort.Ints(s)
return s
}
func SortedStringKeys(m interface{}) []string {
v := reflect.ValueOf(m)
if v.Kind() != reflect.Map {