Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use std maps #21763

Merged
merged 4 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ require (
github.com/tendermint/go-amino v0.16.0
gitlab.com/yawning/secp256k1-voi v0.0.0-20230925100816-f2616030848b
golang.org/x/crypto v0.27.0
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc
golang.org/x/sync v0.8.0
google.golang.org/genproto/googleapis/api v0.0.0-20240604185151-ef581f913117
google.golang.org/grpc v1.66.2
Expand Down Expand Up @@ -161,6 +160,7 @@ require (
go.etcd.io/bbolt v1.4.0-alpha.0.0.20240404170359-43604f3112c5 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions simsx/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package simsx
import (
"context"
"iter"
"maps"
"math/rand"
"slices"
"strings"
"time"

"golang.org/x/exp/maps"

"cosmossdk.io/core/address"
"cosmossdk.io/core/log"

Expand Down Expand Up @@ -170,11 +169,12 @@ func (s UniqueTypeRegistry) Add(weight uint32, f SimMsgFactoryX) {
// Iterator returns an iterator function for a Go for loop sorted by weight desc.
func (s UniqueTypeRegistry) Iterator() iter.Seq2[uint32, SimMsgFactoryX] {
x := maps.Values(s)
slices.SortFunc(x, func(a, b WeightedFactory) int {
sortedWeightedFactory := slices.SortedFunc(x, func(a, b WeightedFactory) int {
return a.Compare(b)
})

return func(yield func(uint32, SimMsgFactoryX) bool) {
for _, v := range x {
for _, v := range sortedWeightedFactory {
if !yield(v.Weight, v.Factory) {
return
}
Expand Down
11 changes: 5 additions & 6 deletions simsx/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package simsx
import (
"errors"
"fmt"
"maps"
"slices"
"sort"
"strings"
"sync"
"sync/atomic"

"golang.org/x/exp/maps"

sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
)
Expand Down Expand Up @@ -237,14 +235,15 @@ func (s *ExecutionSummary) Add(module, url string, status ReporterStatus, commen
func (s *ExecutionSummary) String() string {
s.mx.RLock()
defer s.mx.RUnlock()
keys := maps.Keys(s.counts)
sort.Strings(keys)
keys := slices.Sorted(maps.Keys(s.counts))
var sb strings.Builder
for _, key := range keys {
sb.WriteString(fmt.Sprintf("%s: %d\n", key, s.counts[key]))
}
for m, c := range s.skipReasons {
sb.WriteString(fmt.Sprintf("%d\t%s: %q\n", sum(maps.Values(c)), m, maps.Keys(c)))
values := maps.Values(c)
keys := maps.Keys(c)
sb.WriteString(fmt.Sprintf("%d\t%s: %q\n", sum(slices.Collect(values)), m, slices.Collect(keys)))
}
return sb.String()
}
Expand Down
Loading