(
BisectArgs { a, x, lo, hi, key }: BisectArgs,
vm: &VirtualMachine,
)
| 84 | #[inline] |
| 85 | #[pyfunction] |
| 86 | fn bisect_right( |
| 87 | BisectArgs { a, x, lo, hi, key }: BisectArgs, |
| 88 | vm: &VirtualMachine, |
| 89 | ) -> PyResult<usize> { |
| 90 | let (mut lo, mut hi) = as_usize(lo, hi, a.length(vm)?, vm)?; |
| 91 | |
| 92 | while lo < hi { |
| 93 | // Handles issue 13496. |
| 94 | let mid = (lo + hi) / 2; |
| 95 | let a_mid = a.get_item(&mid, vm)?; |
| 96 | let comp = if let Some(ref key) = key { |
| 97 | key.call((a_mid,), vm)? |
| 98 | } else { |
| 99 | a_mid |
| 100 | }; |
| 101 | if x.rich_compare_bool(&comp, PyComparisonOp::Lt, vm)? { |
| 102 | hi = mid; |
| 103 | } else { |
| 104 | lo = mid + 1; |
| 105 | } |
| 106 | } |
| 107 | Ok(lo) |
| 108 | } |
| 109 | |
| 110 | #[pyfunction] |
| 111 | fn insort_left(BisectArgs { a, x, lo, hi, key }: BisectArgs, vm: &VirtualMachine) -> PyResult { |
no test coverage detected