aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Giorshev <johngiorshev@gmail.com>2025-07-06 18:41:28 +0000
committerGopher Robot <gobot@golang.org>2025-07-07 09:13:08 -0700
commita995269a9383d90a3bdd029989bafc8fc3b19dc3 (patch)
tree8d25fd7d382847b25636f504f44e433d6b7d011f
parent6c3b5a2798c83d583cb37dba9f39c47300d19f1f (diff)
downloadgo-a995269a9383d90a3bdd029989bafc8fc3b19dc3.tar.xz
sort: clarify Less doc
clarifies the requirements for Less Fixes https://github.com/golang/go/issues/73420 Change-Id: I7d49b10fad78c618d946b3bb161ce19680ede47a GitHub-Last-Rev: 7a49ad81923048bfc99b265dd89f012eefcf5699 GitHub-Pull-Request: golang/go#74333 Reviewed-on: https://go-review.googlesource.com/c/go/+/683275 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@google.com> Reviewed-by: Carlos Amedee <carlos@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
-rw-r--r--src/sort/sort.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/sort/sort.go b/src/sort/sort.go
index b27ecabdd5..fd3cd6dabf 100644
--- a/src/sort/sort.go
+++ b/src/sort/sort.go
@@ -26,13 +26,15 @@ type Interface interface {
// Sort may place equal elements in any order in the final result,
// while Stable preserves the original input order of equal elements.
//
- // Less must describe a transitive ordering:
+ // Less must describe a [Strict Weak Ordering]. For example:
// - if both Less(i, j) and Less(j, k) are true, then Less(i, k) must be true as well.
// - if both Less(i, j) and Less(j, k) are false, then Less(i, k) must be false as well.
//
// Note that floating-point comparison (the < operator on float32 or float64 values)
- // is not a transitive ordering when not-a-number (NaN) values are involved.
+ // is not a strict weak ordering when not-a-number (NaN) values are involved.
// See Float64Slice.Less for a correct implementation for floating-point values.
+ //
+ // [Strict Weak Ordering]: https://en.wikipedia.org/wiki/Weak_ordering#Strict_weak_orderings
Less(i, j int) bool
// Swap swaps the elements with indexes i and j.