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

Replace exp/slices with slices from standard library #626

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Changelog

* [CHANGE] Replace `exp/slices` package with `slices` from standard library. #626
Juneezee marked this conversation as resolved.
Show resolved Hide resolved
* [CHANGE] Add new metric `slow_request_server_throughput` to track the throughput of slow queries. #619
* [CHANGE] Log middleware updated to honor `logRequestHeaders` in all logging scenarios. #615
* [CHANGE] Roll back the gRPC dependency to v1.65.0 to allow downstream projects to avoid a performance regression and maybe a bug in v1.66.0. #581
Expand Down
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] {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The constraints.Ordered from golang.org/x/exp/constraints is also included into Go 1.21 as cmp.Ordered. See https://pkg.go.dev/cmp#Ordered

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
Loading