From cde38c966dad075c4c24694d4f02d71de3ab957a Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 7 Feb 2024 13:36:46 -0800 Subject: [PATCH] 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 --- src/slices/sort.go | 8 ++++---- 1 file 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) -- 2.48.1