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

Function bisect

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

This function searches for a tuple of given values (`target`) among the given rows (`item_columns`) using the bisection algorithm. It assumes that `item_columns` is sorted according to `sort_options` and returns the insertion index of `target`. Template argument `SIDE` being `true`/`false` means left/right insertion.

(
    item_columns: &[ArrayRef],
    target: &[ScalarValue],
    sort_options: &[SortOptions],
)

Source from the content-addressed store, hash-verified

149/// is sorted according to `sort_options` and returns the insertion index of `target`.
150/// Template argument `SIDE` being `true`/`false` means left/right insertion.
151pub fn bisect<const SIDE: bool>(
152 item_columns: &[ArrayRef],
153 target: &[ScalarValue],
154 sort_options: &[SortOptions],
155) -> Result<usize> {
156 let low: usize = 0;
157 let high: usize = item_columns
158 .first()
159 .ok_or_else(|| _internal_datafusion_err!("Column array shouldn't be empty"))?
160 .len();
161 let compare_fn = |current: &[ScalarValue], target: &[ScalarValue]| {
162 let cmp = compare_rows(current, target, sort_options)?;
163 Ok(if SIDE { cmp.is_lt() } else { cmp.is_le() })
164 };
165 find_bisect_point(item_columns, target, compare_fn, low, high)
166}
167
168/// This function searches for a tuple of given values (`target`) among a slice of
169/// the given rows (`item_columns`) using the bisection algorithm. The slice starts

Callers

nothing calls this directly

Calls 4

compare_rowsFunction · 0.85
find_bisect_pointFunction · 0.85
lenMethod · 0.45
firstMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…