4 /// Uses a sorted slice `data: &[E]` as a kind of "multi-map". The
5 /// `key_fn` extracts a key of type `K` from the data, and this
6 /// function finds the range of elements that match the key. `data`
7 /// must have been sorted as if by a call to `sort_by_key` for this to
9 pub fn binary_search_slice<E, K>(data: &'d [E], key_fn: impl Fn(&E) -> K, key: &K) -> &'d [E]
13 let mid = match data.binary_search_by_key(key, &key_fn) {
18 // We get back *some* element with the given key -- so
19 // search backwards to find the *first* one.
21 // (It'd be more efficient to use a "galloping" search
22 // here, but it's not really worth it for small-ish
26 if key_fn(&data[start - 1]) == *key {
33 // Now search forward to find the *last* one.
35 // (It'd be more efficient to use a "galloping" search
36 // here, but it's not really worth it for small-ish
38 let mut end = mid + 1;
41 if key_fn(&data[end]) == *key {