mirror of
https://github.com/golang/go
synced 2024-11-22 00:34:40 -07:00
sort.Search: slightly more precise wording in comment
(+ some cosmetic changes) R=iant, iant2 CC=golang-dev https://golang.org/cl/3076041
This commit is contained in:
parent
bac478da1c
commit
8f651ff742
@ -27,7 +27,7 @@ package sort
|
|||||||
// data[i-1] < x && x <= data[i]
|
// data[i-1] < x && x <= data[i]
|
||||||
//
|
//
|
||||||
// where data[-1] is assumed to be smaller than any x and data[n] is
|
// where data[-1] is assumed to be smaller than any x and data[n] is
|
||||||
// assumed to be larger than any x. Thus 0 <= i <= n and i is the first
|
// assumed to be larger than any x. Thus 0 <= i <= n and i is the smallest
|
||||||
// index of x if x is present in the data. It is the responsibility of
|
// index of x if x is present in the data. It is the responsibility of
|
||||||
// the caller to verify the actual presence by testing if i < n and
|
// the caller to verify the actual presence by testing if i < n and
|
||||||
// data[i] == x.
|
// data[i] == x.
|
||||||
@ -42,6 +42,7 @@ package sort
|
|||||||
// } else {
|
// } else {
|
||||||
// // elem is not present in data
|
// // elem is not present in data
|
||||||
// }
|
// }
|
||||||
|
//
|
||||||
func Search(n int, f func(int) bool) int {
|
func Search(n int, f func(int) bool) int {
|
||||||
i, j := 0, n
|
i, j := 0, n
|
||||||
for i+1 < j {
|
for i+1 < j {
|
||||||
@ -55,11 +56,11 @@ func Search(n int, f func(int) bool) int {
|
|||||||
j = h
|
j = h
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// test the final element that the loop did not.
|
// test the final element that the loop did not
|
||||||
if i < j && f(i) {
|
if i < j && f(i) {
|
||||||
|
// data[i] < x
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user