summaryrefslogtreecommitdiff
path: root/lib/std/search.myr
diff options
context:
space:
mode:
authorandrewchambers <andrewchamberss@gmail.com>2016-07-23 15:59:21 +1200
committerOri Bernstein <ori@eigenstate.org>2016-07-22 20:59:21 -0700
commitb24fd14c329aa00b0d9703864f875258164216c4 (patch)
tree5b93ec3b2c7a380b78483a0c0b1a8e5b9df4e951 /lib/std/search.myr
parentb0556e8d98eb7ab7cdc0826de7cdcfcef935db82 (diff)
downloadmc-b24fd14c329aa00b0d9703864f875258164216c4.tar.gz
make bsearch use unsigned indexes (#118)
Diffstat (limited to 'lib/std/search.myr')
-rw-r--r--lib/std/search.myr5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/std/search.myr b/lib/std/search.myr
index 98ba862..e5abd99 100644
--- a/lib/std/search.myr
+++ b/lib/std/search.myr
@@ -1,5 +1,6 @@
use "cmp"
use "option"
+use "types"
pkg std =
generic lsearch : (sl : @t[:], key : @k, cmp : (v : @t, k : @k -> order) -> option(@idx::(integral,numeric)))
@@ -21,7 +22,7 @@ generic lsearch = {sl, key, cmp
/* binary search over a sorted list of values. */
generic bsearch = {sl, key, cmp
- var hi, lo, mid
+ var hi, lo, mid : usize
lo = 0
hi = sl.len - 1
@@ -32,7 +33,7 @@ generic bsearch = {sl, key, cmp
| `After: hi = mid - 1
| `Before: lo = mid + 1
| `Equal:
- -> `Some mid
+ -> `Some (mid : @idx)
;;
;;
-> `None