Skip to main content

merge_chains

Function merge_chains 

Source
pub fn merge_chains<D, T, R, Sink>(
    list1: FetchIter<'_, D, T, R>,
    list2: FetchIter<'_, D, T, R>,
    sink: Sink,
    stash: &mut Vec<Column<(D, T, R)>>,
)
where D: Columnar, for<'a> Ref<'a, D>: Copy + Ord, T: Columnar + Default + Clone + PartialOrder, for<'a> Ref<'a, T>: Copy + Ord, R: Columnar + Default + Semigroup + for<'a> Semigroup<Ref<'a, R>>, Sink: FnMut(PagedColumn<(D, T, R)>),
Expand description

Two-way merge driver. Reuses today’s per-chunk gallop / ship-threshold logic from Column::merge_from, but pulls heads from FetchIter and emits finished output chunks through sink after routing them through the pager exposed by FetchIter::pager.

stash is a pool of empty Column::Typed chunks. Drained heads and shipped result buffers get recycled into it; the next result chunk is pulled from it instead of starting from a zero-capacity default. This matches the recycling discipline the upstream differential_dataflow merge-batcher carries via Merger::merge’s stash parameter.

Whole-chunk passthrough: heads arrive materialized from FetchIter, so peeking endpoints is free. When the current head on one side sorts entirely before the current record on the other side, ship it wholesale and skip the per-record merge. Gated on positions[i] == 0 so we hand the head off intact — partial-tail passthrough would need a 1-input merge_from to copy the tail, which is what the inner loop’s gallop already covers.