diff options
author | Ian Lance Taylor <iant@golang.org> | 2024-02-07 13:36:46 -0800 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2024-02-07 23:54:41 +0000 |
commit | cde38c966dad075c4c24694d4f02d71de3ab957a (patch) | |
tree | 4c4c2ee53da9e8ca376453b8f59cf55af6be8cbe /src/slices | |
parent | 23ac1599abfc558edce5841323e2c679b094fc26 (diff) | |
download | go-cde38c966dad075c4c24694d4f02d71de3ab957a.tar.gz go-cde38c966dad075c4c24694d4f02d71de3ab957a.zip |
slices: document that BinarySearch[Func] return earliest position
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>
Diffstat (limited to 'src/slices')
-rw-r--r-- | src/slices/sort.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/slices/sort.go b/src/slices/sort.go index d5e998ce1e..4c20a2943c 100644 --- a/src/slices/sort.go +++ b/src/slices/sort.go @@ -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) |