(
BisectArgs { a, x, lo, hi, key }: BisectArgs,
vm: &VirtualMachine,
)
| 58 | #[inline] |
| 59 | #[pyfunction] |
| 60 | fn bisect_left( |
| 61 | BisectArgs { a, x, lo, hi, key }: BisectArgs, |
| 62 | vm: &VirtualMachine, |
| 63 | ) -> PyResult<usize> { |
| 64 | let (mut lo, mut hi) = as_usize(lo, hi, a.length(vm)?, vm)?; |
| 65 | |
| 66 | while lo < hi { |
| 67 | // Handles issue 13496. |
| 68 | let mid = (lo + hi) / 2; |
| 69 | let a_mid = a.get_item(&mid, vm)?; |
| 70 | let comp = if let Some(ref key) = key { |
| 71 | key.call((a_mid,), vm)? |
| 72 | } else { |
| 73 | a_mid |
| 74 | }; |
| 75 | if comp.rich_compare_bool(&x, PyComparisonOp::Lt, vm)? { |
| 76 | lo = mid + 1; |
| 77 | } else { |
| 78 | hi = mid; |
| 79 | } |
| 80 | } |
| 81 | Ok(lo) |
| 82 | } |
| 83 | |
| 84 | #[inline] |
| 85 | #[pyfunction] |
no test coverage detected