rust_algorithm_club/searching/exponential_search/
mod.rsuse crate::searching::binary_search;
pub fn exponential_search<T>(arr: &[T], target: &T) -> Result<usize, usize>
where
T: PartialOrd,
{
let size = arr.len();
if size == 0 {
return Err(0);
}
let mut hi = 1_usize; while hi < size && arr[hi] < *target {
hi <<= 1;
}
let lo = hi >> 1; binary_search(&arr[lo..size.min(hi + 1)], target)
.map(|index| lo + index) .map_err(|index| lo + index)
}
#[cfg(test)]
mod base {
use super::*;
sorted_no_duplicate_cases!(exponential_search);
}