MCPcopy Create free account
hub / github.com/apache/datafusion / find_bisect_point

Function find_bisect_point

datafusion/common/src/utils/mod.rs:174–194  ·  view source on GitHub ↗

This function searches for a tuple of given values (`target`) among a slice of the given rows (`item_columns`) using the bisection algorithm. The slice starts at the index `low` and ends at the index `high`. The boolean-valued function `compare_fn` specifies whether we bisect on the left (by returning `false`), or on the right (by returning `true`) when we compare the target value with the current

(
    item_columns: &[ArrayRef],
    target: &[ScalarValue],
    compare_fn: F,
    mut low: usize,
    mut high: usize,
)

Source from the content-addressed store, hash-verified

172/// or on the right (by returning `true`) when we compare the target value with
173/// the current value as we iteratively bisect the input.
174pub fn find_bisect_point<F>(
175 item_columns: &[ArrayRef],
176 target: &[ScalarValue],
177 compare_fn: F,
178 mut low: usize,
179 mut high: usize,
180) -> Result<usize>
181where
182 F: Fn(&[ScalarValue], &[ScalarValue]) -> Result<bool>,
183{
184 while low < high {
185 let mid = ((high - low) / 2) + low;
186 let val = get_row_at_idx(item_columns, mid)?;
187 if compare_fn(&val, target)? {
188 low = mid + 1;
189 } else {
190 high = mid;
191 }
192 }
193 Ok(low)
194}
195
196/// This function searches for a tuple of given values (`target`) among the given
197/// rows (`item_columns`) via a linear scan. It assumes that `item_columns` is sorted

Callers 1

bisectFunction · 0.85

Calls 1

get_row_at_idxFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…