1 Star 4 Fork 11

王布衣 / pandas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
vector_sort.go 1.78 KB
一键复制 编辑 原始数据 按行查看 历史
package pandas
import "gitee.com/quant1x/num"
func (this vector[T]) Len() int {
return len(this)
}
// Less 实现sort.Interface接口的比较元素方法
func (this vector[T]) Less(i, j int) bool {
type_ := this.Type()
if type_ == SERIES_TYPE_BOOL {
values := this.Values().([]bool)
var (
a = int(0)
b = int(0)
)
if values[i] {
a = 1
}
if values[j] {
b = 1
}
return a < b
} else if type_ == SERIES_TYPE_INT64 {
values := this.Values().([]int64)
return values[i] < values[j]
} else if type_ == SERIES_TYPE_FLOAT32 {
values := this.Values().([]float32)
return values[i] < values[j]
} else if type_ == SERIES_TYPE_FLOAT64 {
values := this.Values().([]float64)
return values[i] < values[j]
} else if type_ == SERIES_TYPE_STRING {
values := this.Values().([]string)
return values[i] < values[j]
} else {
// SERIES_TYPE_INVAILD
// 应该到不了这里, Len()会返回0
panic(num.ErrUnsupportedType)
}
return false
}
// Swap 实现sort.Interface接口的交换元素方法
func (this vector[T]) Swap(i, j int) {
type_ := this.Type()
if type_ == SERIES_TYPE_BOOL {
values := this.Values().([]bool)
values[i], values[j] = values[j], values[i]
} else if type_ == SERIES_TYPE_INT64 {
values := this.Values().([]int64)
values[i], values[j] = values[j], values[i]
} else if type_ == SERIES_TYPE_FLOAT32 {
values := this.Values().([]float32)
values[i], values[j] = values[j], values[i]
} else if type_ == SERIES_TYPE_FLOAT64 {
values := this.Values().([]float64)
values[i], values[j] = values[j], values[i]
} else if type_ == SERIES_TYPE_STRING {
values := this.Values().([]string)
values[i], values[j] = values[j], values[i]
} else {
// SERIES_TYPE_INVAILD
// 应该到不了这里, Len()会返回0
panic(num.ErrUnsupportedType)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/pandas.git
git@gitee.com:quant1x/pandas.git
quant1x
pandas
pandas
v1.4.0

搜索帮助

344bd9b3 5694891 D2dac590 5694891