Bump go version to 1.21

Allows us to use the much faster builtin min/max functions
for two variable min/max
This commit is contained in:
Kovid Goyal
2023-08-09 11:58:16 +05:30
parent f125ffe3e0
commit 49ea26968c
17 changed files with 44 additions and 53 deletions

View File

@@ -3,6 +3,7 @@
package utils
import (
"cmp"
"fmt"
"os"
"path/filepath"
@@ -98,19 +99,13 @@ func sort_with_key[T any, C constraints.Ordered](stable bool, s []T, key func(a
for i, x := range s {
temp[i].val, temp[i].key = x, key(x)
}
cmp := func(a, b t) int {
if a.key < b.key {
return -1
}
if a.key > b.key {
return 1
}
return 0
key_cmp := func(a, b t) int {
return cmp.Compare(a.key, b.key)
}
if stable {
slices.SortStableFunc(temp, cmp)
slices.SortStableFunc(temp, key_cmp)
} else {
slices.SortFunc(temp, cmp)
slices.SortFunc(temp, key_cmp)
}
for i, x := range temp {
s[i] = x.val