-
Notifications
You must be signed in to change notification settings - Fork 0
/
keysort.go
86 lines (70 loc) · 1.94 KB
/
keysort.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package keysort
import (
"sort"
)
// String sorts the provided slice given the provided key function.
//
// The function panics if the provided interface is not a slice.
func String(slice interface{}, key func(i int) string) {
sort.Slice(slice, func(i, j int) bool {
return key(i) < key(j)
})
}
func StringStable(slice interface{}, key func(i int) string) {
sort.SliceStable(slice, func(i, j int) bool {
return key(i) < key(j)
})
}
// StringIsSorted tests whether a slice is sorted.
//
// The function panics if the provided interface is not a slice.
func StringIsSorted(slice interface{}, key func(i int) string) bool {
return sort.SliceIsSorted(slice, func(i, j int) bool {
return key(i) < key(j)
})
}
func Int(slice interface{}, key func(i int) int) {
sort.Slice(slice, func(i, j int) bool {
return key(i) < key(j)
})
}
func IntStable(slice interface{}, key func(i int) int) {
sort.SliceStable(slice, func(i, j int) bool {
return key(i) < key(j)
})
}
func IntIsSorted(slice interface{}, key func(i int) int) bool {
return sort.SliceIsSorted(slice, func(i, j int) bool {
return key(i) < key(j)
})
}
func UInt(slice interface{}, key func(i int) uint) {
sort.Slice(slice, func(i, j int) bool {
return key(i) < key(j)
})
}
func UIntStable(slice interface{}, key func(i int) uint) {
sort.SliceStable(slice, func(i, j int) bool {
return key(i) < key(j)
})
}
func UIntIsSorted(slice interface{}, key func(i int) uint) bool {
return sort.SliceIsSorted(slice, func(i, j int) bool {
return key(i) < key(j)
})
}
func Float64(slice interface{}, key func(i int) float64) {
sort.Slice(slice, func(i, j int) bool {
return key(i) < key(j)
})
}
func Float64Stable(slice interface{}, key func(i int) float64) {
sort.SliceStable(slice, func(i, j int) bool {
return key(i) < key(j)
})
}
func Float64IsSorted(slice interface{}, key func(i int) float64) bool {
return sort.SliceIsSorted(slice, func(i, j int) bool {
return key(i) < key(j)
})
}