我想整理一下[]uint 。 这有意义吗? 是否有一些我对uint s缺失的东西让它们变得难以辨认? 我注意到sort包有一个IntSlice和Float64Slice ,但没有任何uint 。
如果uint 是可排序的,那么我可以只复制他们用于sort.IntSlice Len() , Less(i, j int)和Swap(i, j int)的sort.IntSlice吗?
I want to sort a slice of []uint. Does this make sense? Is there something I'm missing about uints that make them unsortable? I notice that the sort package has an IntSlice and Float64Slice, but nothing for uint.
If uints are sortable, then can I just copy the same implementation for Len(), Less(i, j int) and Swap(i, j int) that they've used for the sort.IntSlice?
最满意答案
对于1.7,您可以对实现sort.Interface的任何切片进行排序,以获得[] uint切片的别名类型并使用sort.Sort(接口) 。 在Go 1.8中,您可以选择使用sort.Slice 。 请参阅此处的示例
As for 1.7, you can sort any slice that implements sort.Interface for an alias type of your []uint slice and using sort.Sort(Interface) . In Go 1.8, you will have the option to use sort.Slice. See the example here
更多推荐
发布评论