-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsort.go
51 lines (40 loc) · 1.18 KB
/
sort.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
package semver
import "sort"
// Sorts versions Ascending via the sorts standard lib package.
// resulting order: 1.0.0, 1.1.0, 2.0.0.
type Ascending []Version
var _ sort.Interface = Ascending{}
// Returns the number of items of the slice.
// Implements sort.Interface.
func (l Ascending) Len() int {
return len(l)
}
// Returns true if item[j] is less than item[i].
// Implements sort.Interface.
func (l Ascending) Less(i, j int) bool {
return l[i].LessThan(l[j])
}
// Swaps the position of two items in the list.
// Implements sort.Interface.
func (l Ascending) Swap(i, j int) {
l[i], l[j] = l[j], l[i]
}
// Sorts versions Descending via the sorts standard lib package.
// resulting order: 2.0.0, 1.1.0, 1.0.0.
type Descending []Version
var _ sort.Interface = Descending{}
// Returns the number of items of the slice.
// Implements sort.Interface.
func (l Descending) Len() int {
return len(l)
}
// Returns true if item[j] is less than item[i].
// Implements sort.Interface.
func (l Descending) Less(i, j int) bool {
return l[i].GreaterThan(l[j])
}
// Swaps the position of two items in the list.
// Implements sort.Interface.
func (l Descending) Swap(i, j int) {
l[i], l[j] = l[j], l[i]
}