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:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user