perf: use build-in min/max function instead

This commit is contained in:
tiny-craft
2023-08-16 10:15:17 +08:00
parent 8bb64449ce
commit 3c8221f43f
3 changed files with 3 additions and 14 deletions

View File

@@ -20,11 +20,6 @@ func MaxWithIndex[T Hashable](items ...T) (T, int) {
return items[selIndex], selIndex
}
func Max[T Hashable](items ...T) T {
val, _ := MaxWithIndex(items...)
return val
}
// MinWithIndex 查找所有元素中的最小值
func MinWithIndex[T Hashable](items ...T) (T, int) {
selIndex := -1
@@ -40,11 +35,6 @@ func MinWithIndex[T Hashable](items ...T) (T, int) {
return items[selIndex], selIndex
}
func Min[T Hashable](items ...T) T {
val, _ := MinWithIndex(items...)
return val
}
// Clamp 返回限制在minVal和maxVal范围内的value
func Clamp[T Hashable](value T, minVal T, maxVal T) T {
if minVal > maxVal {