Skip to main content

gallop

Function gallop 

Source
pub(crate) fn gallop(
    upper: usize,
    lower: &mut usize,
    cmp: impl FnMut(usize) -> bool,
)
Expand description

Advance *lower past every position in [*lower, upper) where cmp returns true.

On return, *lower is the first index >= initial *lower where cmp returns false, or upper if cmp holds through the end.

Takes the predicate as FnMut(usize) -> bool rather than a value-bearing closure so callers can index whichever subset of the input columns they actually need to compare — for the merger’s (d, t)-keyed sort, this lets each probe touch only the D and T leaf views, skipping the diff column.

Compared to a linear scan, this is O(log K) for a run of length K satisfying cmp — useful when one side of a sorted merge has long runs dominated by the other side.