Skip to content
Open
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
53 changes: 0 additions & 53 deletions set/ordered.go

This file was deleted.

11 changes: 6 additions & 5 deletions set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,26 @@
package set

import (
"cmp"
"sort"
)

// Empty is public since it is used by some internal API objects for conversions between external
// string arrays and internal sets, and conversion logic requires public types today.
type Empty struct{}

// Set is a set of the same type elements, implemented via map[ordered]struct{} for minimal memory consumption.
type Set[E ordered] map[E]Empty
// Set is a set of the same type elements, implemented via map[cmp.Ordered]struct{} for minimal memory consumption.
type Set[E cmp.Ordered] map[E]Empty

Check failure on line 29 in set/set.go

View workflow job for this annotation

GitHub Actions / lint

invalid map key type E (missing comparable constraint) (typecheck)

// New creates a new set.
func New[E ordered](items ...E) Set[E] {
func New[E cmp.Ordered](items ...E) Set[E] {
ss := Set[E]{}
ss.Insert(items...)
return ss
}

// KeySet creates a Set[E] from a keys of a map[E](? extends interface{}).
func KeySet[E ordered, A any](theMap map[E]A) Set[E] {
func KeySet[E cmp.Ordered, A any](theMap map[E]A) Set[E] {

Check failure on line 39 in set/set.go

View workflow job for this annotation

GitHub Actions / lint

invalid map key type E (missing comparable constraint) (typecheck)
ret := Set[E]{}
for key := range theMap {
ret.Insert(key)
Expand Down Expand Up @@ -158,12 +159,12 @@
return s.Len() == s2.Len() && s.IsSuperset(s2)
}

type sortableSlice[E ordered] []E
type sortableSlice[E cmp.Ordered] []E

func (s sortableSlice[E]) Len() int {
return len(s)
}
func (s sortableSlice[E]) Less(i, j int) bool { return s[i] < s[j] }

Check failure on line 167 in set/set.go

View workflow job for this annotation

GitHub Actions / lint

invalid operation: s[i] < s[j] (type parameter E is not comparable with <) (typecheck)
func (s sortableSlice[E]) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

// SortedList returns the contents as a sorted slice.
Expand Down
3 changes: 2 additions & 1 deletion set/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package set

import (
"cmp"
"reflect"
"testing"
)
Expand Down Expand Up @@ -369,7 +370,7 @@ func TestSetClearInSeparateFunction(t *testing.T) {
}
}

func clearSetAndAdd[T ordered](s Set[T], a T) {
func clearSetAndAdd[T cmp.Ordered](s Set[T], a T) {
s.Clear()
s.Insert(a)
}
Expand Down
Loading