From: Ian Lance Taylor Date: Wed, 7 Feb 2024 21:36:46 +0000 (-0800) Subject: slices: document that BinarySearch[Func] return earliest position X-Git-Tag: go1.23rc1~1282 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=cde38c966dad075c4c24694d4f02d71de3ab957a;p=gostls13.git 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 Auto-Submit: Ian Lance Taylor Reviewed-by: Ian Lance Taylor LUCI-TryBot-Result: Go LUCI --- 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)