Skip to content

Commit

Permalink
sorting uses slices package
Browse files Browse the repository at this point in the history
  • Loading branch information
dimus committed Sep 28, 2023
1 parent 90c51b7 commit b530cd7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Add: sorting uses `slices` package.

## [v1.7.5] - 2023-09-26 Tue

- Add: CSV and TSV files provide now verbatim authorship instead of normalized
Expand Down
16 changes: 8 additions & 8 deletions ent/parser/output.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package parser

import (
"sort"
"cmp"
"slices"
"strings"

"github.com/gnames/gnparser/ent/parsed"
Expand Down Expand Up @@ -88,14 +89,13 @@ func prepareWarnings(ws map[parsed.Warning]struct{}) []parsed.QualityWarning {
i++
}

sort.Slice(res, func(i, j int) bool {
if res[i].Quality > res[j].Quality {
return true
}
if res[i].Quality < res[j].Quality {
return false
slices.SortFunc(res, func(a, b parsed.QualityWarning) int {
res := cmp.Compare(b.Quality, a.Quality)
if res != 0 {
return res
}
return res[i].Warning.String() < res[j].Warning.String()
return cmp.Compare(a.Warning.String(), b.Warning.String())
})

return res
}
6 changes: 4 additions & 2 deletions tools/quality.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore

// quality.go generates a markdown file that describes meaning of each quality
Expand All @@ -6,8 +7,9 @@ package main

import (
"fmt"
"slices"

"github.com/gnames/gnparser/ent/parsed"
"sort"
)

var body = `# Quality categories
Expand All @@ -28,7 +30,7 @@ func main() {

for _, v := range []int{2, 3, 4} {
warns := warnsMap[v]
sort.Strings(warns)
slices.Sort(warns)
item := fmt.Sprintf("\n\n## Quality %d\n", v)
for i := range warns {
warn := fmt.Sprintf("\n- %s", warns[i])
Expand Down

0 comments on commit b530cd7

Please sign in to comment.