Skip to content

Commit d9b8796

Browse files
committed
sort: clarify doc on less
1 parent 49cdf0c commit d9b8796

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/sort/sort.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,20 @@ type Interface interface {
2121
// Less reports whether the element with index i
2222
// must sort before the element with index j.
2323
//
24+
// Less must satisfy [Strict Weak Ordering]. For example:
25+
// - if both Less(i, j) and Less(j, k) are true, then Less(i, k) must be true as well.
26+
// - if both Less(i, j) and Less(j, k) are false, then Less(i, k) must be false as well.
27+
//
2428
// If both Less(i, j) and Less(j, i) are false,
2529
// then the elements at index i and j are considered equal.
2630
// Sort may place equal elements in any order in the final result,
2731
// while Stable preserves the original input order of equal elements.
2832
//
29-
// Less must describe a transitive ordering:
30-
// - if both Less(i, j) and Less(j, k) are true, then Less(i, k) must be true as well.
31-
// - if both Less(i, j) and Less(j, k) are false, then Less(i, k) must be false as well.
32-
//
3333
// Note that floating-point comparison (the < operator on float32 or float64 values)
34-
// is not a transitive ordering when not-a-number (NaN) values are involved.
34+
// is not a strict weak ordering when not-a-number (NaN) values are involved.
3535
// See Float64Slice.Less for a correct implementation for floating-point values.
36+
//
37+
// [Strict Weak Ordering]: https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings
3638
Less(i, j int) bool
3739

3840
// Swap swaps the elements with indexes i and j.

0 commit comments

Comments
 (0)