]> Cypherpunks repositories - gostls13.git/commitdiff
slices: document that BinarySearch[Func] return earliest position
authorIan Lance Taylor <iant@golang.org>
Wed, 7 Feb 2024 21:36:46 +0000 (13:36 -0800)
committerGopher Robot <gobot@golang.org>
Wed, 7 Feb 2024 23:54:41 +0000 (23:54 +0000)
Fixes #65446

Change-Id: I08dc512fb1f0101eb8aac8767cdf582360699559
Reviewed-on: https://go-review.googlesource.com/c/go/+/562345
Reviewed-by: Eli Bendersky <eliben@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/slices/sort.go

index d5e998ce1e2c2b7b0533bbca897fe2183154e0c2..4c20a2943c42da8b44cbba2b2d8a40067bb68f6d 100644 (file)
@@ -117,10 +117,10 @@ func MaxFunc[S ~[]E, E any](x S, cmp func(a, b E) int) E {
        return m
 }
 
-// BinarySearch searches for target in a sorted slice and returns the position
-// where target is found, or the position where target would appear in the
-// sort order; it also returns a bool saying whether the target is really found
-// in the slice. The slice must be sorted in increasing order.
+// BinarySearch searches for target in a sorted slice and returns the earliest
+// position where target is found, or the position where target would appear
+// in the sort order; it also returns a bool saying whether the target is
+// really found in the slice. The slice must be sorted in increasing order.
 func BinarySearch[S ~[]E, E cmp.Ordered](x S, target E) (int, bool) {
        // Inlining is faster than calling BinarySearchFunc with a lambda.
        n := len(x)