mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
first version of obidemerge, obijoin and a new filter for obicleandb but to be finnished
Former-commit-id: 8a1ed26e5548c30db75644c294d478ec4d753f19
This commit is contained in:
37
pkg/obistats/sort.go
Normal file
37
pkg/obistats/sort.go
Normal file
@ -0,0 +1,37 @@
|
||||
package obistats
|
||||
|
||||
//
|
||||
// Dupplicated code from internal module available at :
|
||||
// https://github.com/golang-design/bench.git
|
||||
//
|
||||
|
||||
import (
|
||||
"math"
|
||||
"sort"
|
||||
)
|
||||
|
||||
// An Order defines a sort order for a table.
|
||||
// It reports whether t.Rows[i] should appear before t.Rows[j].
|
||||
type Order func(t *Table, i, j int) bool
|
||||
|
||||
// ByName sorts tables by the Benchmark name column
|
||||
func ByName(t *Table, i, j int) bool {
|
||||
return t.Rows[i].Benchmark < t.Rows[j].Benchmark
|
||||
}
|
||||
|
||||
// ByDelta sorts tables by the Delta column,
|
||||
// reversing the order when larger is better (for "speed" results).
|
||||
func ByDelta(t *Table, i, j int) bool {
|
||||
return math.Abs(t.Rows[i].PctDelta)*float64(t.Rows[i].Change) <
|
||||
math.Abs(t.Rows[j].PctDelta)*float64(t.Rows[j].Change)
|
||||
}
|
||||
|
||||
// Reverse returns the reverse of the given order.
|
||||
func Reverse(order Order) Order {
|
||||
return func(t *Table, i, j int) bool { return order(t, j, i) }
|
||||
}
|
||||
|
||||
// Sort sorts a Table t (in place) by the given order.
|
||||
func Sort(t *Table, order Order) {
|
||||
sort.SliceStable(t.Rows, func(i, j int) bool { return order(t, i, j) })
|
||||
}
|
Reference in New Issue
Block a user