二分查找算法错误
brookxs opened this issue · comments
fast.go 里面的find的二分查找算法写错了
func (f *FastSort) find(target *uint32) (bool, int) {
low := 0
high := f.count - 1
for low <= high {
mid := (low + high) / 2
if f.data[mid].Id == *target {
return true, mid
} else if f.data[mid].Id < *target { // 这里的小于号应该是大于号
high = mid - 1
} else {
low = mid + 1
}
}
return false, -1
//for index, item := range f.data {
// if item.Id == *target {
// return true, index
// }
//}
//return false, -1
}