1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 00:22:41 +08:00
This commit is contained in:
2023-08-25 15:31:00 +08:00
parent 04aecd4abc
commit b0a97978d8
58 changed files with 1330 additions and 476 deletions

View File

@ -1,8 +1,10 @@
package sets
import (
"slices"
"github.com/charlienet/go-mixed/expr"
"golang.org/x/exp/constraints"
"golang.org/x/exp/slices"
)
type sorted_set[T constraints.Ordered] struct {
@ -50,8 +52,12 @@ func (s *sorted_set[T]) Asc() Set[T] {
func (s *sorted_set[T]) Desc() Set[T] {
keys := s.sorted
slices.SortFunc(keys, func(a, b T) bool {
return a > b
slices.SortFunc(keys, func(a, b T) int {
if a == b {
return 0
}
return expr.Ternary(a > b, -1, 1)
})
return &sorted_set[T]{