mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Plenty of small bugs
Former-commit-id: 42c7fab7d65906c80ab4cd32da6867ff21842ea8
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user