@@ -9,15 +9,27 @@ import (
9
9
"math/bits"
10
10
)
11
11
12
- // Slice sorts the slice x given the provided less function.
12
+ // Slice sorts the slice x given the provided less function.
13
13
// It panics if x is not a slice.
14
14
//
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.
17
17
// For a stable sort, use [SliceStable].
18
18
//
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.
21
33
//
22
34
// Note: in many situations, the newer [slices.SortFunc] function is more
23
35
// ergonomic and runs faster.
0 commit comments