ref: b24fd14c329aa00b0d9703864f875258164216c4
parent: b0556e8d98eb7ab7cdc0826de7cdcfcef935db82
author: andrewchambers <andrewchamberss@gmail.com>
date: Sat Jul 23 11:59:21 EDT 2016
make bsearch use unsigned indexes (#118)
--- 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 @@
/* 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 @@
| `After: hi = mid - 1
| `Before: lo = mid + 1
| `Equal:
- -> `Some mid
+ -> `Some (mid : @idx)
;;
;;
-> `None
--- a/lib/std/types.myr
+++ b/lib/std/types.myr
@@ -2,7 +2,7 @@
pkg std =
type size = sys.size /* spans entire address space */
- type usize = sys.usize /* signed size */
+ type usize = sys.usize /* unsigned size */
type off = sys.off /* file offsets */
type intptr = sys.intptr /* can hold any pointer losslessly */
type time = sys.time /* milliseconds since epoch */
--- a/lib/sys/systypes.myr
+++ b/lib/sys/systypes.myr
@@ -1,6 +1,6 @@
pkg sys =
type size = int64 /* spans entire address space */
- type usize = int64 /* signed size */
+ type usize = uint64 /* unsigned size */
type off = int64 /* file offsets */
type intptr = uint64/* can hold any pointer losslessly */
type time = int64 /* milliseconds since epoch */