pub fn pack<C: Chunk>(
input: &mut VecDeque<C>,
done: bool,
out: &mut VecDeque<C>,
combine: impl FnMut(&mut C, C),
split: impl FnMut(C, usize) -> (C, C),
seal: impl FnMut(C) -> C,
)Expand description
Maximal-packing driver an implementor’s Chunk::settle may delegate to.
Holds a carry chunk under construction, grown by combine until it reaches
TARGET (then emitted) and emitted early when the next chunk can’t be absorbed
without exceeding TARGET; over-sized chunks are peeled with split. Each
committed chunk is passed through seal (the compress / spill hook — use the
identity closure when there’s nothing to do). The closures are the only
layout-specific pieces:
combine(&mut acc, next)— appendnextontoacc(caller guarantees their lengths sum to at mostTARGET, andnextfollowsaccin one sorted, consolidated chain), so packing a run of small chunks stays linear.split(chunk, n)— the firstnupdates and the remaininglen - n.seal(chunk)— commit a chunk (e.g. compress or spill); identity to keep it.