Skip to content

Commit 3802688

Browse files
Benson Marguliespull[bot]
Benson Margulies
authored andcommitted
slices: add documentation on incomparable items in SortFunc
Change-Id: Ib289008c0e9b5e83c37c9b6b316f3f5de8ac339a Reviewed-on: https://go-review.googlesource.com/c/go/+/592617 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
1 parent 20420e4 commit 3802688

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/slices/sort.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ func Sort[S ~[]E, E cmp.Ordered](x S) {
2121
// SortFunc sorts the slice x in ascending order as determined by the cmp
2222
// function. This sort is not guaranteed to be stable.
2323
// cmp(a, b) should return a negative number when a < b, a positive number when
24-
// a > b and zero when a == b.
24+
// a > b and zero when a == b or a and b are incomparable in the sense of
25+
// a strict weak ordering.
2526
//
2627
// SortFunc requires that cmp is a strict weak ordering.
2728
// See https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings.
29+
// The function should return 0 for incomparable items.
2830
func SortFunc[S ~[]E, E any](x S, cmp func(a, b E) int) {
2931
n := len(x)
3032
pdqsortCmpFunc(x, 0, n, bits.Len(uint(n)), cmp)

0 commit comments

Comments
 (0)