Skip to content

Commit

Permalink
Replace exp/slices with slices from standard library (#626)
Browse files Browse the repository at this point in the history
* Replace `exp/slices` with `slices` from standard library

The experimental functions in `golang.org/x/exp/slices` are now
available in the standard library in Go 1.21 [1].

[1]: https://go.dev/doc/go1.21#slices

---------

Signed-off-by: Eng Zer Jun <[email protected]>
Co-authored-by: Arve Knudsen <[email protected]>
  • Loading branch information
Juneezee and aknuds1 authored Dec 16, 2024
1 parent e27df29 commit 0450f2b
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 22 deletions.
8 changes: 4 additions & 4 deletions loser/loser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

package loser

import "golang.org/x/exp/constraints"
import "cmp"

func New[E constraints.Ordered](lists [][]E, maxVal E) *Tree[E] {
func New[E cmp.Ordered](lists [][]E, maxVal E) *Tree[E] {
nLists := len(lists)
t := Tree[E]{
maxVal: maxVal,
Expand All @@ -23,12 +23,12 @@ func New[E constraints.Ordered](lists [][]E, maxVal E) *Tree[E] {
// A loser tree is a binary tree laid out such that nodes N and N+1 have parent N/2.
// We store M leaf nodes in positions M...2M-1, and M-1 internal nodes in positions 1..M-1.
// Node 0 is a special node, containing the winner of the contest.
type Tree[E constraints.Ordered] struct {
type Tree[E cmp.Ordered] struct {
maxVal E
nodes []node[E]
}

type node[E constraints.Ordered] struct {
type node[E cmp.Ordered] struct {
index int // This is the loser for all nodes except the 0th, where it is the winner.
value E // Value copied from the loser node, or winner for node 0.
items []E // Only populated for leaf nodes.
Expand Down
6 changes: 3 additions & 3 deletions loser/loser_test.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package loser_test

import (
"cmp"
"fmt"
"math"
"math/rand"
"slices"
"testing"

"github.com/stretchr/testify/require"
"golang.org/x/exp/constraints"
"golang.org/x/exp/slices"

"github.com/grafana/dskit/loser"
)

func checkTreeEqual[E constraints.Ordered](t *testing.T, tree *loser.Tree[E], expected []E, msg ...interface{}) {
func checkTreeEqual[E cmp.Ordered](t *testing.T, tree *loser.Tree[E], expected []E, msg ...interface{}) {
t.Helper()
actual := []E{}

Expand Down
1 change: 0 additions & 1 deletion ring/example/local/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ require (
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.17.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
Expand Down
3 changes: 1 addition & 2 deletions ring/partition_instance_ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package ring

import (
"fmt"
"slices"
"time"

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

type PartitionRingReader interface {
Expand Down
2 changes: 1 addition & 1 deletion ring/partition_instance_ring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package ring

import (
"fmt"
"slices"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
)

func TestPartitionInstanceRing_GetReplicationSetsForOperation(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions ring/partition_ring.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"fmt"
"math"
"math/rand"
"slices"
"strconv"
"time"

"golang.org/x/exp/slices"

shardUtil "github.com/grafana/dskit/ring/shard"
)

Expand Down
3 changes: 1 addition & 2 deletions ring/partition_ring_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import (
"fmt"
"html/template"
"net/http"
"slices"
"sort"
"strconv"
"time"

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

//go:embed partition_ring_status.gohtml
Expand Down
2 changes: 1 addition & 1 deletion ring/partition_ring_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package ring

import (
"fmt"
"slices"
"strconv"
"strings"
"time"

"github.com/gogo/protobuf/proto"
"golang.org/x/exp/slices"

"github.com/grafana/dskit/kv/codec"
"github.com/grafana/dskit/kv/memberlist"
Expand Down
2 changes: 1 addition & 1 deletion ring/partition_ring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"math"
"math/rand"
"slices"
"strconv"
"sync"
"testing"
Expand All @@ -12,7 +13,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)

func TestPartitionRing_ActivePartitionForKey(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions ring/spread_minimizing_token_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import (
"fmt"
"math"
"regexp"
"slices"
"sort"
"strconv"

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

const (
Expand Down
2 changes: 1 addition & 1 deletion ring/spread_minimizing_token_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"fmt"
"math"
"math/rand"
"slices"
"testing"
"time"

"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion ring/token_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package ring

import (
"math"
"slices"

"github.com/pkg/errors"
"golang.org/x/exp/slices" // using exp/slices until moving to go 1.21.
)

// TokenRanges describes token ranges owned by an instance.
Expand Down
2 changes: 1 addition & 1 deletion ring/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package ring
import (
"context"
"math"
"slices"
"sort"
"time"

"github.com/go-kit/log"
"golang.org/x/exp/slices"

"github.com/grafana/dskit/backoff"
"github.com/grafana/dskit/netutil"
Expand Down

0 comments on commit 0450f2b

Please sign in to comment.