MCPcopy Index your code
hub / github.com/RustPython/RustPython / bisect_left

Function bisect_left

crates/stdlib/src/bisect.rs:60–82  ·  view source on GitHub ↗
(
        BisectArgs { a, x, lo, hi, key }: BisectArgs,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

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]

Callers 1

insort_leftFunction · 0.70

Calls 5

as_usizeFunction · 0.85
rich_compare_boolMethod · 0.80
lengthMethod · 0.45
get_itemMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected