Go 降序排序 取 Top N
作者:
光剑书架上的书 | 来源:发表于
2022-06-28 01:14 被阅读0次func top(result *[]*competition_detail.BrandWord, topN int) {
sort.SliceStable(*result, func(i, j int) bool {
return (*result)[i].ProductFrequency > (*result)[j].ProductFrequency
})
if len(*result) > topN {
*result = (*result)[0:topN]
}
}
type BrandWord struct {
ProductPropertyValue string `thrift:"product_property_value,1" json:"product_property_value"`
ProductFrequency int64 `thrift:"product_frequency,2" json:"product_frequency"`
}
本文标题:Go 降序排序 取 Top N
本文链接:https://www.haomeiwen.com/subject/nofavrtx.html
网友评论