MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / binary_search_values_by_key

Method binary_search_values_by_key

cranelift/entity/src/primary.rs:215–224  ·  view source on GitHub ↗

Performs a binary search on the values with a key extraction function. Assumes that the values are sorted by the key extracted by the function. If the value is found then `Ok(K)` is returned, containing the entity key of the matching value. If there are multiple matches, then any one of the matches could be returned. If the value is not found then Err(K) is returned, containing the entity key

(&'a self, b: &B, f: F)

Source from the content-addressed store, hash-verified

213 /// If the value is not found then Err(K) is returned, containing the entity key
214 /// where a matching element could be inserted while maintaining sorted order.
215 pub fn binary_search_values_by_key<'a, B, F>(&'a self, b: &B, f: F) -> Result<K, K>
216 where
217 F: FnMut(&'a V) -> B,
218 B: Ord,
219 {
220 self.elems
221 .binary_search_by_key(b, f)
222 .map(|i| K::new(i))
223 .map_err(|i| K::new(i))
224 }
225
226 /// Analog of `get_raw` except that a raw pointer is returned rather than a
227 /// mutable reference.

Callers

nothing calls this directly

Calls 3

binary_search_by_keyMethod · 0.80
newFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected