Skip to content

Commit

Permalink
update util/sets to use standard package cmp
Browse files Browse the repository at this point in the history
Kubernetes-commit: c26bb7eb85aeb059c127a478f1c6abc512c0e6ce
  • Loading branch information
xgp01 authored and k8s-publishing-bot committed Nov 6, 2023
1 parent fa98d6e commit 8398822
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 56 deletions.
53 changes: 0 additions & 53 deletions pkg/util/sets/ordered.go

This file was deleted.

7 changes: 4 additions & 3 deletions pkg/util/sets/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package sets

import (
"cmp"
"sort"
)

Expand Down Expand Up @@ -193,7 +194,7 @@ func (s1 Set[T]) Equal(s2 Set[T]) bool {
return len(s1) == len(s2) && s1.IsSuperset(s2)
}

type sortableSliceOfGeneric[T ordered] []T
type sortableSliceOfGeneric[T cmp.Ordered] []T

func (g sortableSliceOfGeneric[T]) Len() int { return len(g) }
func (g sortableSliceOfGeneric[T]) Less(i, j int) bool { return less[T](g[i], g[j]) }
Expand All @@ -203,7 +204,7 @@ func (g sortableSliceOfGeneric[T]) Swap(i, j int) { g[i], g[j] = g[j], g[i]
//
// This is a separate function and not a method because not all types supported
// by Generic are ordered and only those can be sorted.
func List[T ordered](s Set[T]) []T {
func List[T cmp.Ordered](s Set[T]) []T {
res := make(sortableSliceOfGeneric[T], 0, len(s))
for key := range s {
res = append(res, key)
Expand Down Expand Up @@ -236,6 +237,6 @@ func (s Set[T]) Len() int {
return len(s)
}

func less[T ordered](lhs, rhs T) bool {
func less[T cmp.Ordered](lhs, rhs T) bool {
return lhs < rhs
}

0 comments on commit 8398822

Please sign in to comment.