The result of sort.Search is in the interval [0,n);
specifically, if no entry is found, the result is n
and not -1.
R=dsymonds
CC=golang-dev
https://golang.org/cl/
4982041
i := sort.Search(len(z), func(i int) bool {
return name <= z[i].Name
})
- if i < 0 {
+ if i >= len(z) {
return -1, false
}
+ // 0 <= i < len(z)
if z[i].Name == name {
return i, true
}
j := sort.Search(len(z), func(i int) bool {
return name <= z[i].Name
})
- if j < 0 {
+ if j >= len(z) {
return -1, false
}
+ // 0 <= j < len(z)
if strings.HasPrefix(z[j].Name, name) {
return i + j, false
}