github.com/iikira/iikira-go-utils@v0.0.0-20230610031953-f2cb11cde33a/requester/downloader/sort.go (about) 1 package downloader 2 3 type ( 4 // ByLeftDesc 根据剩余下载量倒序排序 5 ByLeftDesc struct { 6 WorkerList 7 } 8 ) 9 10 // Len 返回长度 11 func (wl WorkerList) Len() int { 12 return len(wl) 13 } 14 15 // Swap 交换 16 func (wl WorkerList) Swap(i, j int) { 17 wl[i], wl[j] = wl[j], wl[i] 18 } 19 20 // Less 实现倒序 21 func (wl ByLeftDesc) Less(i, j int) bool { 22 return wl.WorkerList[i].wrange.Len() > wl.WorkerList[j].wrange.Len() 23 }