Skip to content

Commit 1a8bbda

Browse files
committed
fix doc on sort.Slice
1 parent 7b26389 commit 1a8bbda

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/sort/slice.go

+17-5
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,27 @@ import (
99
"math/bits"
1010
)
1111

12-
// Slice sorts the slice x given the provided less function.
12+
// Slice sorts the slice x given the provided less function.
1313
// It panics if x is not a slice.
1414
//
15-
// The sort is not guaranteed to be stable: equal elements
16-
// may be reversed from their original order.
15+
// The sort is not guaranteed to be stable: equal elements may be reversed from
16+
// their original order.
1717
// For a stable sort, use [SliceStable].
1818
//
19-
// The less function must satisfy the same requirements as
20-
// the Interface type's Less method.
19+
// The less function reports whether the element with index i must sort before
20+
// the element with index j.
21+
//
22+
// If both less(i, j) and less(j, i) are false, then the elements at index i and
23+
// j are considered equal.
24+
//
25+
// The less function must satisfy strict weak ordering requirements. See
26+
// https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings. In
27+
// contrast, [SliceStable] does not have as stringent requirements.
28+
//
29+
// Note that floating-point comparison (the < operator on float32 or float64
30+
// values) is not a transitive ordering when not-a-number (NaN) values are
31+
// involved. See Float64Slice.Less for a correct implementation for
32+
// floating-point values.
2133
//
2234
// Note: in many situations, the newer [slices.SortFunc] function is more
2335
// ergonomic and runs faster.

0 commit comments

Comments
 (0)