diff options
Diffstat (limited to 'worker')
-rw-r--r-- | worker/types/thread.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/worker/types/thread.go b/worker/types/thread.go index 48e4a002..7c0cc5b8 100644 --- a/worker/types/thread.go +++ b/worker/types/thread.go @@ -3,6 +3,7 @@ package types import ( "errors" "fmt" + "sort" ) type Thread struct { @@ -120,3 +121,15 @@ func (s ByUID) Less(i, j int) bool { maxUID_j := getMaxUID(s[j]) return maxUID_i < maxUID_j } + +func SortThreadsBy(toSort []*Thread, sortBy []uint32) { + // build a map from sortBy + uidMap := make(map[uint32]int) + for i, uid := range sortBy { + uidMap[uid] = i + } + // sortslice of toSort with less function of indexing the map sortBy + sort.Slice(toSort, func(i, j int) bool { + return uidMap[getMaxUID(toSort[i])] < uidMap[getMaxUID(toSort[j])] + }) +} |