MCPcopy Create free account
hub / github.com/google/gapid / SortValues

Function SortValues

core/data/slice/sort.go:65–93  ·  view source on GitHub ↗

SortValues sorts the reflect.Values in the slice s into ascending order. All the elements of e need to be of the type elTy. Numbers are sorted numerically. Booleans are sorted with false before true. Everything else is sorted lexicographically by first converting to string with Sprintf.

(s []reflect.Value, elTy reflect.Type)

Source from the content-addressed store, hash-verified

63// Everything else is sorted lexicographically by first converting to string
64// with Sprintf.
65func SortValues(s []reflect.Value, elTy reflect.Type) {
66 switch elTy.Kind() {
67 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
68 sort.Slice(s, func(i, j int) bool {
69 return s[i].Int() < s[j].Int()
70 })
71 case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
72 sort.Slice(s, func(i, j int) bool {
73 return s[i].Uint() < s[j].Uint()
74 })
75 case reflect.Float32, reflect.Float64:
76 sort.Slice(s, func(i, j int) bool {
77 return s[i].Float() < s[j].Float()
78 })
79 case reflect.Bool:
80 sort.Slice(s, func(i, j int) bool {
81 return !s[i].Bool() && s[j].Bool()
82 })
83 case reflect.String:
84 sort.Slice(s, func(i, j int) bool {
85 return s[i].String() < s[j].String()
86 })
87 default:
88 sort.Slice(s, func(i, j int) bool {
89 a, b := s[i].Interface(), s[j].Interface()
90 return fmt.Sprint(a) < fmt.Sprint(b)
91 })
92 }
93}

Callers

nothing calls this directly

Calls 8

InterfaceMethod · 0.80
SprintMethod · 0.80
KindMethod · 0.65
SliceMethod · 0.65
BoolMethod · 0.65
StringMethod · 0.65
IntMethod · 0.45
UintMethod · 0.45

Tested by

no test coverage detected