pub fn pack<C: Chunk>(
input: &mut VecDeque<C>,
done: bool,
out: &mut VecDeque<C>,
combine: impl FnMut(Vec<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 run of chunks, grown until it reaches TARGET (then emitted as
one chunk) 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(run)— one chunk from a run of at least two (caller guarantees their lengths sum to at mostTARGET, and that they form one sorted, consolidated chain). A run is combined once, when emitted, so packing stays linear even when combining copies its inputs.split(chunk, n)— the firstnupdates and the remaininglen - n.seal(chunk)— commit a chunk (e.g. compress or spill); identity to keep it.