check this code: fn main() { let cfivends = vec![(5,10),(25,30),(40,45),(60,65)]; let…
- User
check this code:
fn main() { let c_fivends = vec![(5,10),(25,30),(40,45),(60,65)]; let c_exons = vec![(32,37),(47,55),(70,80)]; let tx_5end = (43,45);
if let Ok(k) = c_fivends.binary_search_by(|&(start, _)| start.cmp(&tx_5end.0)) { println!("we are inside") } else { println!("we are not inside") };}
current result is "we are not inside". In this case the expected behavior should be "we are inside" because 43 is between 40 and 45. Your solution needs to be the most efficient, fastest and elegant.
- Assistant
To achieve the expected behavior—determining whether the
tx_5endstart position is contained within any of the(start, end)ranges inc_fivends—we can't rely onbinary_search_byalone because it searches for an exact match. However, we need to find a range that contains a value.