-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
slices: add sorting and comparison functions
Now that the `cmp` package exists, sorting and comparison functions from `x/exp/slices` can be ported to the standard library, using the `cmp.Ordered` type and the `cmp.Less` and `cmp.Compare` functions. This move also includes adjustments to the discussions in golang#60091 w.r.t. NaN handling and cmp vs. less functions, and adds Min/Max functions. The final API is taken from golang#60091 (comment) Updates golang#60091 Change-Id: Id7e6c88035b60d4ddd0c48dd82add8e8bc4e22d3 Reviewed-on: https://go-review.googlesource.com/c/go/+/496078 Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Eli Bendersky <[email protected]> Run-TryBot: Eli Bendersky <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
- Loading branch information
Showing
10 changed files
with
2,080 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
pkg slices, func BinarySearchFunc[$0 interface{}, $1 interface{}]([]$0, $1, func($0, $1) int) (int, bool) #60091 | ||
pkg slices, func BinarySearch[$0 cmp.Ordered]([]$0, $0) (int, bool) #60091 | ||
pkg slices, func CompareFunc[$0 interface{}, $1 interface{}]([]$0, []$1, func($0, $1) int) int #60091 | ||
pkg slices, func Compare[$0 cmp.Ordered]([]$0, []$0) int #60091 | ||
pkg slices, func IsSortedFunc[$0 interface{}]([]$0, func($0, $0) int) bool #60091 | ||
pkg slices, func IsSorted[$0 cmp.Ordered]([]$0) bool #60091 | ||
pkg slices, func MaxFunc[$0 interface{}]([]$0, func($0, $0) int) $0 #60091 | ||
pkg slices, func Max[$0 cmp.Ordered]([]$0) $0 #60091 | ||
pkg slices, func MinFunc[$0 interface{}]([]$0, func($0, $0) int) $0 #60091 | ||
pkg slices, func Min[$0 cmp.Ordered]([]$0) $0 #60091 | ||
pkg slices, func SortFunc[$0 interface{}]([]$0, func($0, $0) int) #60091 | ||
pkg slices, func SortStableFunc[$0 interface{}]([]$0, func($0, $0) int) #60091 | ||
pkg slices, func Sort[$0 cmp.Ordered]([]$0) #60091 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.