Skip to content

Commit

Permalink
slices: add documention on incomparable items in SortFunc.
Browse files Browse the repository at this point in the history
Change-Id: I5670e82764f790854a8c5797280ee1d8617980b6
Reviewed-on: https://go-review.googlesource.com/c/exp/+/592655
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
  • Loading branch information
bimargulies-google authored and gopherbot committed Jun 13, 2024
1 parent fc45aab commit 7f521ea
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion slices/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ func Sort[S ~[]E, E constraints.Ordered](x S) {
// SortFunc sorts the slice x in ascending order as determined by the cmp
// function. This sort is not guaranteed to be stable.
// cmp(a, b) should return a negative number when a < b, a positive number when
// a > b and zero when a == b.
// a > b and zero when a == b or when a is not comparable to b in the sense
// of the formal definition of Strict Weak Ordering.
//
// SortFunc requires that cmp is a strict weak ordering.
// See https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings.
// To indicate 'uncomparable', return 0 from the function.
func SortFunc[S ~[]E, E any](x S, cmp func(a, b E) int) {
n := len(x)
pdqsortCmpFunc(x, 0, n, bits.Len(uint(n)), cmp)
Expand Down

0 comments on commit 7f521ea

Please sign in to comment.