aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sort
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sort')
-rw-r--r--lib/sort/sort.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/sort/sort.go b/lib/sort/sort.go
index c7e2b8ce..287f986c 100644
--- a/lib/sort/sort.go
+++ b/lib/sort/sort.go
@@ -70,3 +70,15 @@ func SortBy(toSort []uint32, sortBy []uint32) {
return uidMap[toSort[i]] < uidMap[toSort[j]]
})
}
+
+// SortStringBy sorts the string slice s according to the order given in the
+// order string slice.
+func SortStringBy(s []string, order []string) {
+ m := make(map[string]int)
+ for i, d := range order {
+ m[d] = i
+ }
+ sort.Slice(s, func(i, j int) bool {
+ return m[s[i]] < m[s[j]]
+ })
+}