Closed
Description
Code
src/lib.rs
use std::ops::Index;
use std::cmp::Ordering;
#[inline]
pub fn bsearch<T: PartialOrd + PartialEq>(data: &[T], item: &T) -> Option<usize> {
let (mut l, mut u) = (0, data.len());
loop {
let mp = (l + u) / 2;
match data[mp].partial_cmp(item)? {
Ordering::Equal => return Some(mp),
Ordering::Less => l = mp,
Ordering::Greater => u = mp,
}
if l == u {
return None;
}
}
}
tests/test.rs
extern crate bsearch;
use test::bench::Bencher;
use bsearch::bsearch;
#[bench]
fn test_one_item(b: &mut Bencher) {
assert_eq!(bsearch(&[1], &1), Some(0));
}
Command ran
cargo test
Error
error: internal compiler error: librustc/ich/impls_ty.rs:906: ty::TypeVariants::hash_stable() - Unexpected variant TyInfer(?0).
thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:540:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.26.0-nightly (55c984ee5 2018-03-16) running on x86_64-unknown-linux-gnu
note: compiler flags: -C debuginfo=2 -C incremental
note: some of the compiler flags provided by cargo are hidden
error: Could not compile `bsearch`.
To learn more, run the command again with --verbose.
Metadata
Metadata
Assignees
Labels
No labels