@@ -15,10 +15,10 @@ import (
15
15
"golang.org/x/exp/constraints"
16
16
)
17
17
18
- type Set [T constraints. Ordered ] map [T ]struct {}
18
+ type Set [T comparable ] map [T ]struct {}
19
19
20
20
// SetFromSlice constructs a Set from a slice.
21
- func FromSlice [T constraints. Ordered ](items []T ) Set [T ] {
21
+ func FromSlice [T comparable ](items []T ) Set [T ] {
22
22
// best pre-allocation if there are no duplicates
23
23
res := make (map [T ]struct {}, len (items ))
24
24
for _ , item := range items {
@@ -52,7 +52,7 @@ func (s Set[T]) Remove(item ...T) {
52
52
}
53
53
}
54
54
55
- func New [T constraints. Ordered ](item ... T ) Set [T ] {
55
+ func New [T comparable ](item ... T ) Set [T ] {
56
56
res := make (Set [T ], len (item ))
57
57
res .Add (item ... )
58
58
return res
@@ -70,7 +70,7 @@ func (s Set[T]) String() string {
70
70
// RemoveCommon removes elements from both sets that are in both,
71
71
// leaving only the delta. Useful for Notifier on Set so that
72
72
// oldValue has what has been removed and newValue has what has been added.
73
- func RemoveCommon [T constraints. Ordered ](a , b Set [T ]) {
73
+ func RemoveCommon [T comparable ](a , b Set [T ]) {
74
74
if len (a ) > len (b ) {
75
75
a , b = b , a
76
76
}
@@ -82,8 +82,8 @@ func RemoveCommon[T constraints.Ordered](a, b Set[T]) {
82
82
}
83
83
}
84
84
85
- func (s Set [T ]) Sorted () [] T {
86
- keys := make ([]T , 0 , len (s ))
85
+ func Sort [ Q constraints. Ordered ] (s Set [Q ]) [] Q {
86
+ keys := make ([]Q , 0 , len (s ))
87
87
for k := range s {
88
88
keys = append (keys , k )
89
89
}
0 commit comments