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

Function linear_search

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

This function searches for a tuple of given values (`target`) among the given rows (`item_columns`) via a linear scan. 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

198/// according to `sort_options` and returns the insertion index of `target`.
199/// Template argument `SIDE` being `true`/`false` means left/right insertion.
200pub fn linear_search<const SIDE: bool>(
201 item_columns: &[ArrayRef],
202 target: &[ScalarValue],
203 sort_options: &[SortOptions],
204) -> Result<usize> {
205 let low: usize = 0;
206 let high: usize = item_columns
207 .first()
208 .ok_or_else(|| _internal_datafusion_err!("Column array shouldn't be empty"))?
209 .len();
210 let compare_fn = |current: &[ScalarValue], target: &[ScalarValue]| {
211 let cmp = compare_rows(current, target, sort_options)?;
212 Ok(if SIDE { cmp.is_lt() } else { cmp.is_le() })
213 };
214 search_in_slice(item_columns, target, compare_fn, low, high)
215}
216
217/// This function searches for a tuple of given values (`target`) among a slice of
218/// the given rows (`item_columns`) via a linear scan. The slice starts at the index

Callers

nothing calls this directly

Calls 4

compare_rowsFunction · 0.85
search_in_sliceFunction · 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…