...
Source file
src/sort/slice.go
Documentation: sort
1
2
3
4
5
6
7 package sort
8
9 import "reflect"
10
11
12
13
14
15
16
17 func Slice(slice interface{}, less func(i, j int) bool) {
18 rv := reflect.ValueOf(slice)
19 swap := reflect.Swapper(slice)
20 length := rv.Len()
21 quickSort_func(lessSwap{less, swap}, 0, length, maxDepth(length))
22 }
23
24
25
26
27
28 func SliceStable(slice interface{}, less func(i, j int) bool) {
29 rv := reflect.ValueOf(slice)
30 swap := reflect.Swapper(slice)
31 stable_func(lessSwap{less, swap}, rv.Len())
32 }
33
34
35
36
37 func SliceIsSorted(slice interface{}, less func(i, j int) bool) bool {
38 rv := reflect.ValueOf(slice)
39 n := rv.Len()
40 for i := n - 1; i > 0; i-- {
41 if less(i, i-1) {
42 return false
43 }
44 }
45 return true
46 }
47
View as plain text