Skip to content

Commit 864b3d6

Browse files
ianlancetaylorgopherbot
authored andcommitted
slices: update BinarySearchFunc docs for CL 464456
In CL 464456 we updated BinarySearchFunc to permit different types for the slice element and the target. Update the docs accordingly. For golang/go#57348 Fixes golang/go#59685 Change-Id: I8bc3b81051628807fb2426a425101b8bad041ff9 Reviewed-on: https://go-review.googlesource.com/c/exp/+/485995 Reviewed-by: Eli Bendersky <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
1 parent 0354be2 commit 864b3d6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

slices/sort.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,12 @@ func BinarySearch[E constraints.Ordered](x []E, target E) (int, bool) {
8181
}
8282

8383
// BinarySearchFunc works like BinarySearch, but uses a custom comparison
84-
// function. The slice must be sorted in increasing order, where "increasing" is
85-
// defined by cmp. cmp(a, b) is expected to return an integer comparing the two
86-
// parameters: 0 if a == b, a negative number if a < b and a positive number if
87-
// a > b.
84+
// function. The slice must be sorted in increasing order, where "increasing"
85+
// is defined by cmp. cmp should return 0 if the slice element matches
86+
// the target, a negative number if the slice element precedes the target,
87+
// or a positive number if the slice element follows the target.
88+
// cmp must implement the same ordering as the slice, such that if
89+
// cmp(a, t) < 0 and cmp(b, t) >= 0, then a must precede b in the slice.
8890
func BinarySearchFunc[E, T any](x []E, target T, cmp func(E, T) int) (int, bool) {
8991
n := len(x)
9092
// Define cmp(x[-1], target) < 0 and cmp(x[n], target) >= 0 .

0 commit comments

Comments
 (0)