Skip to content

Commit

Permalink
address tim's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
logicalhan committed May 5, 2023
1 parent c3703b2 commit 10cedcc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions set/ordered.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ limitations under the License.

package set

// Ordered is a constraint that permits any ordered type: any type
// ordered is a constraint that permits any ordered type: any type
// that supports the operators < <= >= >.
// If future releases of Go add new ordered types,
// this constraint will be modified to include them.
type Ordered interface {
type ordered interface {
integer | float | ~string
}

Expand Down
12 changes: 6 additions & 6 deletions set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ import (
// 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[comparable]struct{} for minimal memory consumption.
type Set[E Ordered] map[E]Empty
// 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

// New creates a new set.
func New[E Ordered](items ...E) Set[E] {
func New[E 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 ordered, A any](theMap map[E]A) Set[E] {
ret := Set[E]{}
for key := range theMap {
ret.Insert(key)
Expand Down Expand Up @@ -98,7 +98,7 @@ func (s Set[E]) Union(s2 Set[E]) Set[E] {
return result
}

// Len returns the size of the set.
// Len returns the number of elements in the set.
func (s Set[E]) Len() int {
return len(s)
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func (s Set[E]) Equal(s2 Set[E]) bool {
return s.Len() == s.Len() && s.IsSuperset(s2)
}

type sortableSlice[E Ordered] []E
type sortableSlice[E ordered] []E

func (s sortableSlice[E]) Len() int {
return len(s)
Expand Down
4 changes: 2 additions & 2 deletions set/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func TestStringIntersection(t *testing.T) {
}
}

func TestNewSetFromMapKeys(t *testing.T) {
func TestKeySet(t *testing.T) {
m := map[string]string{
"hallo": "world",
"goodbye": "and goodnight",
Expand Down Expand Up @@ -359,7 +359,7 @@ func TestSetClearInSeparateFunction(t *testing.T) {
}
}

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

0 comments on commit 10cedcc

Please sign in to comment.