mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-05-23 08:30:07 -03:00
remove reflection-based slice sort
Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
This commit is contained in:
parent
804bf53f4a
commit
c28f6fa145
@ -59,7 +59,7 @@ func (c *classifier) Classify(content []byte, candidates map[string]float64) []s
|
||||
}
|
||||
|
||||
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))
|
||||
for _, scoredLang := range scoredLangs {
|
||||
sortedLanguages = append(sortedLanguages, scoredLang.language)
|
||||
@ -94,3 +94,9 @@ func (c *classifier) tokenProbability(token, language string) float64 {
|
||||
|
||||
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…
x
Reference in New Issue
Block a user