chore(deps): remove direct dependency on golang.org/x/exp
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
@@ -61,7 +61,6 @@ require (
|
|||||||
github.com/unrolled/secure v1.17.0
|
github.com/unrolled/secure v1.17.0
|
||||||
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342
|
github.com/xrash/smetrics v0.0.0-20250705151800-55b8f293f342
|
||||||
go.uber.org/goleak v1.3.0
|
go.uber.org/goleak v1.3.0
|
||||||
golang.org/x/exp v0.0.0-20251209150349-8475f28825e9
|
|
||||||
golang.org/x/image v0.34.0
|
golang.org/x/image v0.34.0
|
||||||
golang.org/x/net v0.48.0
|
golang.org/x/net v0.48.0
|
||||||
golang.org/x/sync v0.19.0
|
golang.org/x/sync v0.19.0
|
||||||
@@ -130,6 +129,7 @@ require (
|
|||||||
go.yaml.in/yaml/v2 v2.4.2 // indirect
|
go.yaml.in/yaml/v2 v2.4.2 // indirect
|
||||||
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
||||||
golang.org/x/crypto v0.46.0 // indirect
|
golang.org/x/crypto v0.46.0 // indirect
|
||||||
|
golang.org/x/exp v0.0.0-20251209150349-8475f28825e9 // indirect
|
||||||
golang.org/x/mod v0.31.0 // indirect
|
golang.org/x/mod v0.31.0 // indirect
|
||||||
golang.org/x/telemetry v0.0.0-20251203150158-8fff8a5912fc // indirect
|
golang.org/x/telemetry v0.0.0-20251203150158-8fff8a5912fc // indirect
|
||||||
golang.org/x/tools v0.40.0 // indirect
|
golang.org/x/tools v0.40.0 // indirect
|
||||||
|
|||||||
@@ -2,11 +2,15 @@ package number
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"golang.org/x/exp/constraints"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func ParseInt[T constraints.Integer](s string) T {
|
// Integer is a constraint that permits any integer type.
|
||||||
|
type Integer interface {
|
||||||
|
~int | ~int8 | ~int16 | ~int32 | ~int64 |
|
||||||
|
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseInt[T Integer](s string) T {
|
||||||
r, _ := strconv.ParseInt(s, 10, 64)
|
r, _ := strconv.ParseInt(s, 10, 64)
|
||||||
return T(r)
|
return T(r)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"golang.org/x/exp/constraints"
|
"github.com/navidrome/navidrome/utils/number"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Int64N returns a random int64 between 0 and max.
|
// Int64N returns a random int64 between 0 and max.
|
||||||
// This is a reimplementation of math/rand/v2.Int64N using a cryptographically secure random number generator.
|
// This is a reimplementation of math/rand/v2.Int64N using a cryptographically secure random number generator.
|
||||||
func Int64N[T constraints.Integer](max T) int64 {
|
func Int64N[T number.Integer](max T) int64 {
|
||||||
rnd, _ := rand.Int(rand.Reader, big.NewInt(int64(max)))
|
rnd, _ := rand.Int(rand.Reader, big.NewInt(int64(max)))
|
||||||
return rnd.Int64()
|
return rnd.Int64()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,8 @@ import (
|
|||||||
"cmp"
|
"cmp"
|
||||||
"io"
|
"io"
|
||||||
"iter"
|
"iter"
|
||||||
|
"maps"
|
||||||
"slices"
|
"slices"
|
||||||
|
|
||||||
"golang.org/x/exp/maps"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Map[T any, R any](t []T, mapFunc func(T) R) []R {
|
func Map[T any, R any](t []T, mapFunc func(T) R) []R {
|
||||||
@@ -49,11 +48,9 @@ func CompactByFrequency[T comparable](list []T) []T {
|
|||||||
counters[item]++
|
counters[item]++
|
||||||
}
|
}
|
||||||
|
|
||||||
sorted := maps.Keys(counters)
|
return slices.SortedFunc(maps.Keys(counters), func(i, j T) int {
|
||||||
slices.SortFunc(sorted, func(i, j T) int {
|
|
||||||
return cmp.Compare(counters[j], counters[i])
|
return cmp.Compare(counters[j], counters[i])
|
||||||
})
|
})
|
||||||
return sorted
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func MostFrequent[T comparable](list []T) T {
|
func MostFrequent[T comparable](list []T) T {
|
||||||
|
|||||||
Reference in New Issue
Block a user