ref: 96203fff1cc3c06bea79801d9af38c40e556d74a
parent: 51567134bf91de89705a64670abae17514ecc55a
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Dec 6 19:28:45 EST 2016
Fix bsearch on empty slices.
--- a/lib/std/search.myr
+++ b/lib/std/search.myr
@@ -22,7 +22,7 @@
/* binary search over a sorted list of values. */
generic bsearch = {sl, key, cmp
- var hi, lo, mid : usize
+ var hi, lo, mid : size
lo = 0
hi = sl.len - 1
--- a/lib/std/test/search.myr
+++ b/lib/std/test/search.myr
@@ -8,11 +8,13 @@
expect(std.lsearch(sl[:], 33, std.numcmp), `std.Some sl.len - 1)
expect(std.lsearch(sl[:], 5, std.numcmp), `std.Some 2)
expect(std.lsearch(sl[:], 6, std.numcmp), `std.None)
+ expect(std.lsearch(sl[:0], 6, std.numcmp), `std.None)
expect(std.bsearch(sl[:], 1, std.numcmp), `std.Some 0)
expect(std.bsearch(sl[:], 33, std.numcmp), `std.Some sl.len - 1)
expect(std.bsearch(sl[:], 5, std.numcmp), `std.Some 2)
expect(std.bsearch(sl[:], 6, std.numcmp), `std.None)
+ expect(std.bsearch(sl[:0], 1, std.numcmp), `std.None) /* empty slice */
}
const expect = {a, b