1
0
mirror of https://github.com/sjwhitworth/golearn.git synced 2025-04-25 13:48:49 +08:00
golearn/trees/sorter.go
2020-07-25 13:22:15 +05:30

25 lines
357 B
Go

package trees
import (
"sort"
)
type Slice struct {
sort.Float64Slice
Idx []int
}
func (s Slice) Swap(i, j int) {
s.Float64Slice.Swap(i, j)
s.Idx[i], s.Idx[j] = s.Idx[j], s.Idx[i]
}
func NewSlice(n []float64) *Slice {
s := &Slice{Float64Slice: sort.Float64Slice(n), Idx: make([]int, len(n))}
for i := range s.Idx {
s.Idx[i] = i
}
return s
}