mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-10 13:32:24 +00:00
Merge pull request #51 from erizocosmico/feature/no-reflection-sort
remove reflection-based slice sort
This commit is contained in:
commit
78100948c4
@ -59,7 +59,7 @@ func (c *classifier) Classify(content []byte, candidates map[string]float64) []s
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sortLanguagesByScore(scoredLangs []*scoredLanguage) []string {
|
func sortLanguagesByScore(scoredLangs []*scoredLanguage) []string {
|
||||||
sort.SliceStable(scoredLangs, func(i, j int) bool { return scoredLangs[j].score < scoredLangs[i].score })
|
sort.Stable(byScore(scoredLangs))
|
||||||
sortedLanguages := make([]string, 0, len(scoredLangs))
|
sortedLanguages := make([]string, 0, len(scoredLangs))
|
||||||
for _, scoredLang := range scoredLangs {
|
for _, scoredLang := range scoredLangs {
|
||||||
sortedLanguages = append(sortedLanguages, scoredLang.language)
|
sortedLanguages = append(sortedLanguages, scoredLang.language)
|
||||||
@ -94,3 +94,9 @@ func (c *classifier) tokenProbability(token, language string) float64 {
|
|||||||
|
|
||||||
return tokenProb
|
return tokenProb
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type byScore []*scoredLanguage
|
||||||
|
|
||||||
|
func (b byScore) Len() int { return len(b) }
|
||||||
|
func (b byScore) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
|
||||||
|
func (b byScore) Less(i, j int) bool { return b[j].score < b[i].score }
|
||||||
|
Loading…
Reference in New Issue
Block a user