-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsort_range.go
More file actions
99 lines (78 loc) · 2.66 KB
/
Copy pathsort_range.go
File metadata and controls
99 lines (78 loc) · 2.66 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package semver
import "sort"
// AscendingMin sorts ranges Ascending by minimal version via the sort standard lib package.
// resulting order: 1.0.0 - 4.0.0, 1.1.0 - 2.0.0, 2.0.0 - 5.0.0.
type AscendingMin []Range
var _ sort.Interface = AscendingMin{}
// Returns the number of items of the slice.
// Implements sort.Interface.
func (l AscendingMin) Len() int {
return len(l)
}
// Returns true if item[i] should sort before item[j] (descending order).
// Implements sort.Interface.
func (l AscendingMin) Less(i, j int) bool {
return l[i].Min.LessThan(l[j].Min)
}
// Swaps the position of two items in the list.
// Implements sort.Interface.
func (l AscendingMin) Swap(i, j int) {
l[i], l[j] = l[j], l[i]
}
// AscendingMax sorts ranges Ascending by max version via the sort standard lib package.
// resulting order: 1.0.0 - 2.0.0, 0.4.0 - 3.0.0, 0.1.0 - 4.0.0.
type AscendingMax []Range
var _ sort.Interface = AscendingMax{}
// Returns the number of items of the slice.
// Implements sort.Interface.
func (l AscendingMax) Len() int {
return len(l)
}
// Returns true if item[i] should sort before item[j] (descending order).
// Implements sort.Interface.
func (l AscendingMax) Less(i, j int) bool {
return l[i].Max.LessThan(l[j].Max)
}
// Swaps the position of two items in the list.
// Implements sort.Interface.
func (l AscendingMax) Swap(i, j int) {
l[i], l[j] = l[j], l[i]
}
// DescendingMin sorts ranges Descending by min version via the sort standard lib package.
// resulting order: 2.0.0, 1.1.0, 1.0.0.
type DescendingMin []Range
var _ sort.Interface = DescendingMin{}
// Returns the number of items of the slice.
// Implements sort.Interface.
func (l DescendingMin) Len() int {
return len(l)
}
// Returns true if item[i] should sort before item[j] (descending order).
// Implements sort.Interface.
func (l DescendingMin) Less(i, j int) bool {
return l[i].Min.GreaterThan(l[j].Min)
}
// Swaps the position of two items in the list.
// Implements sort.Interface.
func (l DescendingMin) Swap(i, j int) {
l[i], l[j] = l[j], l[i]
}
// DescendingMax sorts ranges Descending by max version via the sort standard lib package.
// resulting order: 2.0.0, 1.1.0, 1.0.0.
type DescendingMax []Range
var _ sort.Interface = DescendingMax{}
// Returns the number of items of the slice.
// Implements sort.Interface.
func (l DescendingMax) Len() int {
return len(l)
}
// Returns true if item[i] should sort before item[j] (descending order).
// Implements sort.Interface.
func (l DescendingMax) Less(i, j int) bool {
return l[i].Max.GreaterThan(l[j].Max)
}
// Swaps the position of two items in the list.
// Implements sort.Interface.
func (l DescendingMax) Swap(i, j int) {
l[i], l[j] = l[j], l[i]
}