sea-team / gofound

GoFound GoLang Full text search go语言全文检索引擎,毫秒级查询。 使用http接口调用,集成Admin管理界面,任何系统都可以使用。

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

二分查找算法错误

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
}