v0.0.38
This commit is contained in:
parent
bdb181cb3a
commit
5e99e07f40
39
langext/sort.go
Normal file
39
langext/sort.go
Normal file
@ -0,0 +1,39 @@
|
||||
package langext
|
||||
|
||||
import "sort"
|
||||
|
||||
func Sort[T OrderedConstraint](arr []T) {
|
||||
sort.Slice(arr, func(i1, i2 int) bool {
|
||||
return arr[i1] < arr[i2]
|
||||
})
|
||||
}
|
||||
|
||||
func SortStable[T OrderedConstraint](arr []T) {
|
||||
sort.SliceStable(arr, func(i1, i2 int) bool {
|
||||
return arr[i1] < arr[i2]
|
||||
})
|
||||
}
|
||||
|
||||
func IsSorted[T OrderedConstraint](arr []T) bool {
|
||||
return sort.SliceIsSorted(arr, func(i1, i2 int) bool {
|
||||
return arr[i1] < arr[i2]
|
||||
})
|
||||
}
|
||||
|
||||
func SortSlice[T any](arr []T, less func(v1, v2 T) bool) {
|
||||
sort.Slice(arr, func(i1, i2 int) bool {
|
||||
return less(arr[i1], arr[i2])
|
||||
})
|
||||
}
|
||||
|
||||
func SortSliceStable[T any](arr []T, less func(v1, v2 T) bool) {
|
||||
sort.SliceStable(arr, func(i1, i2 int) bool {
|
||||
return less(arr[i1], arr[i2])
|
||||
})
|
||||
}
|
||||
|
||||
func IsSliceSorted[T any](arr []T, less func(v1, v2 T) bool) bool {
|
||||
return sort.SliceIsSorted(arr, func(i1, i2 int) bool {
|
||||
return less(arr[i1], arr[i2])
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user