Plenty of small bugs

Former-commit-id: 42c7fab7d65906c80ab4cd32da6867ff21842ea8
This commit is contained in:
Eric Coissac
2024-06-04 16:49:12 +02:00
parent e843d2aa5c
commit 65f5109957
15 changed files with 894 additions and 264 deletions

View File

@ -1,6 +1,7 @@
package obiutils
import (
log "github.com/sirupsen/logrus"
"golang.org/x/exp/constraints"
)
@ -29,3 +30,20 @@ func MinMaxSlice[T constraints.Ordered](vec []T) (min, max T) {
return
}
func MaxMap[K comparable, T constraints.Ordered](values map[K]T) (K, T) {
if len(values) == 0 {
log.Panicf("empty map")
}
var maxKey K
var maxValue T
for k, v := range values {
if v > maxValue {
maxValue = v
maxKey = k
}
}
return maxKey, maxValue
}