MCPcopy Create free account
hub / github.com/DioxusLabs/dioxus-components / find_nearest_binary_search

Function find_nearest_binary_search

primitives/src/virtual/utils.rs:11–15  ·  view source on GitHub ↗

Binary search to find the nearest item at or before the given offset. Returns the index of the item whose `start` position is closest to (but not exceeding) the given offset.

(measurements: &[VirtualItem], offset: u32)

Source from the content-addressed store, hash-verified

9/// Returns the index of the item whose `start` position is closest to
10/// (but not exceeding) the given offset.
11pub(crate) fn find_nearest_binary_search(measurements: &[VirtualItem], offset: u32) -> usize {
12 measurements
13 .binary_search_by(|item| item.start().cmp(&offset))
14 .unwrap_or_else(|idx| idx.saturating_sub(1))
15}
16
17/// Extract indices from a range with overscan applied.
18pub(crate) fn default_range_extractor(

Callers 1

calculate_rangeFunction · 0.85

Calls 1

startMethod · 0.45

Tested by

no test coverage detected