当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
6 Star 9 Fork 1

wzshiming / ffmt
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sort.go 949 Bytes
一键复制 编辑 原始数据 按行查看 历史
wzshiming 提交于 2018-08-22 10:12 . fixes sort
package ffmt
import (
"reflect"
"sort"
)
type valueSlice []reflect.Value
func (p valueSlice) Len() int {
return len(p)
}
func (p valueSlice) Less(i, j int) bool {
pi := p[i]
pj := p[j]
for pi.Kind() == reflect.Interface || pi.Kind() == reflect.Ptr {
pi = pi.Elem()
}
for pj.Kind() == reflect.Interface || pj.Kind() == reflect.Ptr {
pj = pj.Elem()
}
if pi.Kind() == pj.Kind() {
switch pi.Kind() {
case reflect.String:
return pi.String() < pj.String()
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return pi.Int() < pj.Int()
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
return pi.Uint() < pj.Uint()
case reflect.Float32, reflect.Float64:
return pi.Float() < pj.Float()
default:
return true
}
}
return pi.Kind() > pj.Kind()
}
func (p valueSlice) Swap(i, j int) {
p[i], p[j] = p[j], p[i]
}
func (p valueSlice) Sort() {
sort.Sort(p)
}
Go
1
https://gitee.com/wzshiming/ffmt.git
git@gitee.com:wzshiming/ffmt.git
wzshiming
ffmt
ffmt
master

搜索帮助