- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsorting.go
More file actions
Latest commit
54 lines (49 loc) · 1.33 KB
/
Copy pathsorting.go
File metadata and controls
54 lines (49 loc) · 1.33 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
package rtapi
import (
"cmp"
"slices"
)
// Sorting selects a Torrent field and direction.
typeSortingint8
const (
DefaultSortingSorting=iota
ByName
ByNameRev
ByDownRate
ByDownRateRev
ByUpRate
ByUpRateRev
BySize
BySizeRev
ByRatio
ByRatioRev
ByAge
ByAgeRev
ByUpTotal
ByUpTotalRev
)
// Sort orders torrents in place.
func (tTorrents) Sort(aSortingSorting) {
switchaSorting {
caseByName, ByNameRev:
slices.SortFunc(t, func(a, b*Torrent) int { returncmp.Compare(a.Name, b.Name) })
caseByDownRate, ByDownRateRev:
slices.SortFunc(t, func(a, b*Torrent) int { returncmp.Compare(a.DownRate, b.DownRate) })
caseByUpRate, ByUpRateRev:
slices.SortFunc(t, func(a, b*Torrent) int { returncmp.Compare(a.UpRate, b.UpRate) })
caseBySize, BySizeRev:
slices.SortFunc(t, func(a, b*Torrent) int { returncmp.Compare(a.Size, b.Size) })
caseByRatio, ByRatioRev:
slices.SortFunc(t, func(a, b*Torrent) int { returncmp.Compare(a.Ratio, b.Ratio) })
caseByAge, ByAgeRev:
slices.SortFunc(t, func(a, b*Torrent) int { returncmp.Compare(a.Age, b.Age) })
caseByUpTotal, ByUpTotalRev:
slices.SortFunc(t, func(a, b*Torrent) int { returncmp.Compare(a.UpTotal, b.UpTotal) })
default:
return
}
switchaSorting {
caseByNameRev, ByDownRateRev, ByUpRateRev, BySizeRev, ByRatioRev, ByAgeRev, ByUpTotalRev:
slices.Reverse(t)
}
}