Skip to main content

stream_compaction

Function stream_compaction 

Source
pub fn stream_compaction<T: Clone>(
    data: &[T],
    pred: impl Fn(&T) -> bool,
) -> (Vec<T>, Vec<usize>)
Expand description

Stream compaction: retain only elements satisfying a predicate, returning a compacted output together with a scatter index map.

Returns (compacted, scatter_map) where:

  • compacted contains the elements data[i] for which pred(data[i]) is true.
  • scatter_map[j] is the original index i of compacted[j].

This mirrors a GPU stream-compaction pass (prefix-sum → scatter).