forked from Eason-Hua/transmission
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsorting.go
162 lines (138 loc) · 3.94 KB
/
sorting.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package transmission
import "sort"
type Sorting int
const (
SortID Sorting = iota
SortRevID
SortName
SortRevName
SortAge
SortRevAge
SortSize
SortRevSize
SortProgress
SortRevProgress
SortDownSpeed
SortRevDownSpeed
SortUpSpeed
SortRevUpSpeed
SortDownloaded
SortRevDownloaded
SortUploaded
SortRevUploaded
SortRatio
SortRevRatio
)
// sorting types
type (
byID Torrents
byName Torrents
byAge Torrents
bySize Torrents
byProgress Torrents
byDownSpeed Torrents
byUpSpeed Torrents
byDownloaded Torrents
byUploaded Torrents
byRatio Torrents
)
func (t byID) Len() int { return len(t) }
func (t byID) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t byID) Less(i, j int) bool { return t[i].ID < t[j].ID }
func (t byName) Len() int { return len(t) }
func (t byName) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t byName) Less(i, j int) bool { return t[i].Name < t[j].Name }
func (t byAge) Len() int { return len(t) }
func (t byAge) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t byAge) Less(i, j int) bool { return t[i].AddedDate < t[j].AddedDate }
func (t bySize) Len() int { return len(t) }
func (t bySize) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t bySize) Less(i, j int) bool { return t[i].SizeWhenDone < t[j].SizeWhenDone }
func (t byProgress) Len() int { return len(t) }
func (t byProgress) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t byProgress) Less(i, j int) bool { return t[i].PercentDone < t[j].PercentDone }
func (t byDownSpeed) Len() int { return len(t) }
func (t byDownSpeed) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t byDownSpeed) Less(i, j int) bool { return t[i].RateDownload < t[j].RateDownload }
func (t byUpSpeed) Len() int { return len(t) }
func (t byUpSpeed) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t byUpSpeed) Less(i, j int) bool { return t[i].RateUpload < t[j].RateUpload }
func (t byDownloaded) Len() int { return len(t) }
func (t byDownloaded) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t byDownloaded) Less(i, j int) bool { return t[i].DownloadedEver < t[j].DownloadedEver }
func (t byUploaded) Len() int { return len(t) }
func (t byUploaded) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t byUploaded) Less(i, j int) bool { return t[i].UploadedEver < t[j].UploadedEver }
func (t byRatio) Len() int { return len(t) }
func (t byRatio) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t byRatio) Less(i, j int) bool { return t[i].UploadRatio < t[j].UploadRatio }
func (t Torrents) SortID(reverse bool) {
if reverse {
sort.Sort(sort.Reverse(byID(t)))
return
}
sort.Sort(byID(t))
}
func (t Torrents) SortName(reverse bool) {
if reverse {
sort.Sort(sort.Reverse(byName(t)))
return
}
sort.Sort(byName(t))
}
func (t Torrents) SortAge(reverse bool) {
if reverse {
sort.Sort(sort.Reverse(byAge(t)))
return
}
sort.Sort(byAge(t))
}
func (t Torrents) SortSize(reverse bool) {
if reverse {
sort.Sort(sort.Reverse(bySize(t)))
return
}
sort.Sort(bySize(t))
}
func (t Torrents) SortProgress(reverse bool) {
if reverse {
sort.Sort(sort.Reverse(byProgress(t)))
return
}
sort.Sort(byProgress(t))
}
func (t Torrents) SortDownSpeed(reverse bool) {
if reverse {
sort.Sort(sort.Reverse(byDownSpeed(t)))
return
}
sort.Sort(byDownSpeed(t))
}
func (t Torrents) SortUpSpeed(reverse bool) {
if reverse {
sort.Sort(sort.Reverse(byUpSpeed(t)))
return
}
sort.Sort(byUpSpeed(t))
}
func (t Torrents) SortDownloaded(reverse bool) {
if reverse {
sort.Sort(sort.Reverse(byDownloaded(t)))
return
}
sort.Sort(byDownloaded(t))
}
func (t Torrents) SortUploaded(reverse bool) {
if reverse {
sort.Sort(sort.Reverse(byUploaded(t)))
return
}
sort.Sort(byUploaded(t))
}
func (t Torrents) SortRatio(reverse bool) {
if reverse {
sort.Sort(sort.Reverse(byRatio(t)))
return
}
sort.Sort(byRatio(t))
}