排序uint64切片 [英] sorting a uint64 slice in go

查看:106
本文介绍了排序uint64切片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一片uint64( var dirRange [] uint64

sort包有一个函数 sort.Ints()但它需要 [] int ,并且我有 [] uint64

我该怎么办?我可以输入全部分片吗?



谢谢

解决方案

版本1.8,您可以使用更简单的函数 sort.Slice 。在你的情况下,它将如下所示:

  sort.Slice(dirRange,func(i,j int)bool {return dirRange [i]< dirRange [j]})

这样可以避免必须定义任何类型只是为了排序。


I'm writing Go application using Go 1.7rc3.

I have a slice of uint64 (var dirRange []uint64) that I want to sort.

the sort package has a function sort.Ints() but it requires []int and I have []uint64.

what do I do? can I type cast the all slice ?

thanks

解决方案

As of version 1.8, you can use the simpler function sort.Slice. In your case, it would be something like the following:

sort.Slice(dirRange, func(i, j int) bool { return dirRange[i] < dirRange[j] })

This avoids having to define any type just for the sorting.

这篇关于排序uint64切片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆