import (
"fmt"
"sort"
)
func main() {
fs := []float64{1.3, 1.7, 1.0, 1.9, 1.2}
sort.Float64s(fs)
fmt.Println(fs)
}
# go run sort.go
[1 1.2 1.3 1.7 1.9]
Btw. Peter, the sort package implements and uses Quicksort.
func (r ReverseSort) Less(i,j int) bool {
return !r.Interface.Less(i,j)
}
> Wouldn't it be faster (because you don't need the interface
> indirection) to sort with sort.Float64s() and then reverse the result?
You get the interface indirection either way. That's how the sort
package works. I would not expect there to be any speed difference.
There is no penalty for converting to a different interface, if that is
what you mean. You get a new method set; it doesn't convert to the old
method set.
Ian