Fixes binarySearch's bug
This commit is contained in:
parent
a093605ab0
commit
17b8bb8b47
1 changed files with 2 additions and 2 deletions
|
|
@ -94,7 +94,7 @@ proc binarySearch*[T, K](a: openArray[T], key: K,
|
|||
if cmpRes < 1:
|
||||
result = i
|
||||
step = step shr 1
|
||||
if cmpRes != 0: result = -1
|
||||
if cmp(a[result], key) != 0: result = -1
|
||||
else:
|
||||
var b = len
|
||||
var cmpRes: int
|
||||
|
|
@ -108,7 +108,7 @@ proc binarySearch*[T, K](a: openArray[T], key: K,
|
|||
result = mid + 1
|
||||
else:
|
||||
b = mid
|
||||
if result >= len or cmpRes != 0: result = -1
|
||||
if result >= len or cmp(a[result], key) != 0: result = -1
|
||||
|
||||
proc binarySearch*[T](a: openArray[T], key: T): int =
|
||||
## binary search for `key` in `a`. Returns -1 if not found.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue