mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-05 23:55:11 +00:00
*: use slices package for sorting and searching
Signed-off-by: Roman Khimov <roman@nspcc.ru>
This commit is contained in:
parent
6581bd47fc
commit
a1a7e3d708
30 changed files with 158 additions and 181 deletions
|
@ -2,9 +2,10 @@ package query
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"cmp"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"sort"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
|
@ -192,14 +193,18 @@ func queryCandidates(ctx *cli.Context) error {
|
|||
return cli.Exit(err, 1)
|
||||
}
|
||||
|
||||
sort.Slice(vals, func(i, j int) bool {
|
||||
if vals[i].Active != vals[j].Active {
|
||||
return vals[i].Active
|
||||
slices.SortFunc(vals, func(a, b result.Candidate) int {
|
||||
if a.Active && !b.Active {
|
||||
return 1
|
||||
}
|
||||
if vals[i].Votes != vals[j].Votes {
|
||||
return vals[i].Votes > vals[j].Votes
|
||||
if !a.Active && b.Active {
|
||||
return -1
|
||||
}
|
||||
return vals[i].PublicKey.Cmp(&vals[j].PublicKey) == -1
|
||||
res := cmp.Compare(a.Votes, b.Votes)
|
||||
if res != 0 {
|
||||
return res
|
||||
}
|
||||
return a.PublicKey.Cmp(&b.PublicKey)
|
||||
})
|
||||
var res []byte
|
||||
res = fmt.Appendf(res, "Key\tVotes\tCommittee\tConsensus\n")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue