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

remove some of the reliance on the exp pkg #2405

Closed
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
11 changes: 9 additions & 2 deletions api/metrics/multi_gatherer.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,14 @@ func (g *multiGatherer) Register(namespace string, gatherer prometheus.Gatherer)
}

func sortMetrics(m []*dto.MetricFamily) {
slices.SortFunc(m, func(i, j *dto.MetricFamily) bool {
return *i.Name < *j.Name
slices.SortFunc(m, func(i, j *dto.MetricFamily) int {
if *i.Name < *j.Name {
return -1
}
if *i.Name > *j.Name {
return 1
}

return 0
})
}
4 changes: 2 additions & 2 deletions codec/reflectcodec/type_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,10 @@ func (c *genericCodec) marshal(
endOffset = p.Offset
}

slices.SortFunc(sortedKeys, func(a, b keyTuple) bool {
slices.SortFunc(sortedKeys, func(a, b keyTuple) int {
aBytes := p.Bytes[a.startIndex:a.endIndex]
bBytes := p.Bytes[b.startIndex:b.endIndex]
return bytes.Compare(aBytes, bBytes) < 0
return bytes.Compare(aBytes, bBytes)
})

allKeyBytes := slices.Clone(p.Bytes[startOffset:p.Offset])
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ require (
go.uber.org/mock v0.2.0
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.14.0
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df
golang.org/x/exp v0.0.0-20231127185646-65229373498e
golang.org/x/net v0.17.0
golang.org/x/sync v0.3.0
golang.org/x/term v0.13.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -704,8 +704,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME=
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
golang.org/x/exp v0.0.0-20231127185646-65229373498e h1:Gvh4YaCaXNs6dKTlfgismwWZKyjVZXwOPfIyUaqU3No=
golang.org/x/exp v0.0.0-20231127185646-65229373498e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
18 changes: 13 additions & 5 deletions utils/sorting.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,32 @@ type Sortable[T any] interface {

// Sorts the elements of [s].
func Sort[T Sortable[T]](s []T) {
slices.SortFunc(s, T.Less)
slices.SortFunc(s, func(a, b T) int {
if a.Less(b) {
return -1
}
if b.Less(a) {
return 1
}
return 0
})
}

// Sorts the elements of [s] based on their hashes.
func SortByHash[T ~[]byte](s []T) {
slices.SortFunc(s, func(i, j T) bool {
slices.SortFunc(s, func(i, j T) int {
iHash := hashing.ComputeHash256(i)
jHash := hashing.ComputeHash256(j)
return bytes.Compare(iHash, jHash) == -1
return bytes.Compare(iHash, jHash)
})
}

// Sorts a 2D byte slice.
// Each byte slice is not sorted internally; the byte slices are sorted relative
// to one another.
func SortBytes[T ~[]byte](s []T) {
slices.SortFunc(s, func(i, j T) bool {
return bytes.Compare(i, j) == -1
slices.SortFunc(s, func(i, j T) int {
return bytes.Compare(i, j)
})
}

Expand Down