MCPcopy
hub / github.com/google/go-cmp / sort

Method sort

cmp/cmpopts/sort.go:139–155  ·  view source on GitHub ↗
(x interface{})

Source from the content-addressed store, hash-verified

137 (vx.Len() != 0 || vy.Len() != 0)
138}
139func (ms mapSorter) sort(x interface{}) interface{} {
140 src := reflect.ValueOf(x)
141 outType := reflect.StructOf([]reflect.StructField{
142 {Name: "K", Type: src.Type().Key()},
143 {Name: "V", Type: src.Type().Elem()},
144 })
145 dst := reflect.MakeSlice(reflect.SliceOf(outType), src.Len(), src.Len())
146 for i, k := range src.MapKeys() {
147 v := reflect.New(outType).Elem()
148 v.Field(0).Set(k)
149 v.Field(1).Set(src.MapIndex(k))
150 dst.Index(i).Set(v)
151 }
152 sort.Slice(dst.Interface(), func(i, j int) bool { return ms.less(dst, i, j) })
153 ms.checkSort(dst)
154 return dst.Interface()
155}
156func (ms mapSorter) checkSort(v reflect.Value) {
157 for i := 1; i < v.Len(); i++ {
158 if !ms.less(v, i-1, i) {

Callers

nothing calls this directly

Calls 6

lessMethod · 0.95
checkSortMethod · 0.95
TypeMethod · 0.65
LenMethod · 0.65
KeyMethod · 0.45
IndexMethod · 0.45

Tested by

no test coverage detected