Skip to content

Commit

Permalink
refactor: replace golang.org/x/exp/maps with std lib maps pkg
Browse files Browse the repository at this point in the history
This replaces all uses of golang.org/x/exp/maps and refactors code
that sorts keys of a map.
  • Loading branch information
meling committed Dec 17, 2024
1 parent bd10196 commit dd47473
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
8 changes: 3 additions & 5 deletions cmd/latencygen/latency_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import (
"fmt"
"go/format"
"log"
"maps"
"os"
"sort"
"slices"
"strings"
"time"

"golang.org/x/exp/maps"
)

// Run go generate from this directory to generate the latency matrix.
Expand All @@ -30,8 +29,7 @@ func main() {
if err := json.Unmarshal([]byte(latencyMatrix), &allToAllMatrix); err != nil {
log.Fatal(err)
}
keys := maps.Keys(allToAllMatrix)
sort.Strings(keys)
keys := slices.Sorted(maps.Keys(allToAllMatrix))

s := strings.Builder{}
s.WriteString(`package backend
Expand Down
5 changes: 2 additions & 3 deletions crypto/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package crypto
import (
"container/list"
"crypto/sha256"
"maps"
"slices"
"strings"
"sync"

"github.com/relab/hotstuff"
"github.com/relab/hotstuff/modules"
"golang.org/x/exp/maps"
)

type cache struct {
Expand Down Expand Up @@ -106,8 +106,7 @@ func (cache *cache) Verify(signature hotstuff.QuorumSignature, message []byte) b
// BatchVerify verifies the given quorum signature against the batch of messages.
func (cache *cache) BatchVerify(signature hotstuff.QuorumSignature, batch map[hotstuff.ID][]byte) bool {
// sort the list of ids from the batch map
ids := maps.Keys(batch)
slices.Sort(ids)
ids := slices.Sorted(maps.Keys(batch))
var hash hotstuff.Hash
hasher := sha256.New()
// then hash the messages in sorted order
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ require (
github.com/spf13/viper v1.19.0
go-hep.org/x/hep v0.36.0
go.uber.org/zap v1.27.0
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67
golang.org/x/time v0.8.0
gonum.org/v1/plot v0.15.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20241216192217-9240e9c98484
Expand Down Expand Up @@ -76,6 +75,7 @@ require (
go.opentelemetry.io/otel/trace v1.33.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect
golang.org/x/image v0.23.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.32.0 // indirect
Expand Down
5 changes: 2 additions & 3 deletions twins/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"maps"
"reflect"
"slices"
"strings"
Expand All @@ -19,7 +20,6 @@ import (
"github.com/relab/hotstuff/logging"
"github.com/relab/hotstuff/modules"
"github.com/relab/hotstuff/synchronizer"
"golang.org/x/exp/maps"
)

// NodeID is an ID that is unique to a node in the network.
Expand Down Expand Up @@ -403,8 +403,7 @@ func (s NodeSet) Contains(v uint32) bool {

// MarshalJSON returns a JSON representation of the node set.
func (s NodeSet) MarshalJSON() ([]byte, error) {
ids := maps.Keys(s)
slices.Sort(ids)
ids := slices.Sorted(maps.Keys(s))
return json.Marshal(ids)
}

Expand Down

0 comments on commit dd47473

Please sign in to comment.