mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2024-11-14 05:57:25 +01:00
Use simpler sort function
This commit is contained in:
parent
da946472df
commit
41ea9139c6
@ -128,18 +128,7 @@ func medianAnyType[T float64 | float32 | int | int32 | int64](values []T) (T, er
|
|||||||
if len(values) == 0 {
|
if len(values) == 0 {
|
||||||
return 0.0, errors.New("median function requires at least one argument")
|
return 0.0, errors.New("median function requires at least one argument")
|
||||||
}
|
}
|
||||||
slices.SortFunc(
|
slices.Sort(values)
|
||||||
values,
|
|
||||||
func(a T, b T) int {
|
|
||||||
if a < b {
|
|
||||||
return -1
|
|
||||||
} else if a > b {
|
|
||||||
return 1
|
|
||||||
} else {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
var median T
|
var median T
|
||||||
if midPoint := len(values) % 2; midPoint == 0 {
|
if midPoint := len(values) % 2; midPoint == 0 {
|
||||||
median = (values[midPoint-1] + values[midPoint]) / 2
|
median = (values[midPoint-1] + values[midPoint]) / 2
|
||||||
|
Loading…
Reference in New Issue
Block a user