Skip to main content

pack

Function pack 

Source
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) — append next onto acc (caller guarantees their lengths sum to at most TARGET, and next follows acc in one sorted, consolidated chain), so packing a run of small chunks stays linear.
  • split(chunk, n) — the first n updates and the remaining len - n.
  • seal(chunk) — commit a chunk (e.g. compress or spill); identity to keep it.