1
0
Fork 0
mirror of https://github.com/Luzifer/webcheck.git synced 2024-11-08 22:50:01 +00:00
webcheck/vendor/github.com/montanaflynn/stats/util.go

44 lines
922 B
Go
Raw Normal View History

package stats
import (
"sort"
"time"
)
// float64ToInt rounds a float64 to an int
func float64ToInt(input float64) (output int) {
r, _ := Round(input, 0)
return int(r)
}
// unixnano returns nanoseconds from UTC epoch
func unixnano() int64 {
return time.Now().UTC().UnixNano()
}
// copyslice copies a slice of float64s
func copyslice(input Float64Data) Float64Data {
s := make(Float64Data, input.Len())
copy(s, input)
return s
}
// sortedCopy returns a sorted copy of float64s
func sortedCopy(input Float64Data) (copy Float64Data) {
copy = copyslice(input)
sort.Float64s(copy)
return
}
// sortedCopyDif returns a sorted copy of float64s
// only if the original data isn't sorted.
// Only use this if returned slice won't be manipulated!
func sortedCopyDif(input Float64Data) (copy Float64Data) {
if sort.Float64sAreSorted(input) {
return input
}
copy = copyslice(input)
sort.Float64s(copy)
return
}