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

Function bisect_right

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

Source from the content-addressed store, hash-verified

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 {

Callers 1

insort_rightFunction · 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