Function eytzinger::eytzinger_search_by [−][src]
pub fn eytzinger_search_by<'a, T: 'a, F>(data: &'a [T], f: F) -> Option<usize> where
F: FnMut(&'a T) -> Ordering,
Binary searches this eytzinger slice with a comparator function.
The comparator function should implement an order consistent with the sort order
of the underlying eytzinger slice, returning an order code that indicates whether
its argument is Less
, Equal
or Greater
than the desired target.
If a matching value is found then Some
is returned, containing the index of the
matching element; if no match is found then None
is returned.
Examples
use eytzinger::eytzinger_search_by; let s = [3, 1, 5, 0, 2, 4, 6]; assert_eq!(eytzinger_search_by(&s, |x| x.cmp(&3)), Some(0)); assert_eq!(eytzinger_search_by(&s, |x| x.cmp(&5)), Some(2)); assert_eq!(eytzinger_search_by(&s, |x| x.cmp(&6)), Some(6)); assert_eq!(eytzinger_search_by(&s, |x| x.cmp(&7)), None);