#[non_exhaustive]pub enum OutputBound {
OneToOne,
AtMost {
max: usize,
},
Unbounded,
}Expand description
Upper bound on how many outputs an operation produces per input element.
Declared so a caller can size a destination buffer before the operation runs. That is what makes a scan-then-scatter implementation possible: with a per-element bound, exclusive-prefix-summing the per-element counts gives every worker a disjoint write offset, so no lock, no atomic counter, and no dynamically growing vector is needed on the hot path.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
OneToOne
Exactly one output per input. The output index equals the input index.
AtMost
At most max outputs per input element.
Unbounded
The output count cannot be bounded before running.
Callers must fall back to a growable collection. Kept representable and deliberately unpleasant so an operation that could declare a bound is not tempted to shrug.
Implementations§
Source§impl OutputBound
impl OutputBound
Sourcepub const fn upper_bound(self, elements: usize) -> Option<usize>
pub const fn upper_bound(self, elements: usize) -> Option<usize>
Worst-case total outputs for elements inputs, or None if unbounded
or the product would overflow.
Sourcepub const fn is_preallocatable(self, elements: usize) -> bool
pub const fn is_preallocatable(self, elements: usize) -> bool
Whether a caller can preallocate an exact destination for elements.
Sourcepub fn write_offsets(self, counts: &[usize]) -> Option<(Vec<usize>, usize)>
pub fn write_offsets(self, counts: &[usize]) -> Option<(Vec<usize>, usize)>
Exclusive prefix sum of counts, plus the total.
This is the scan that turns “how many outputs does each element make?”
into “where does each element write?”. Returns None if any count
exceeds this bound (a provider contract violation) or the total
overflows. Allocation is the caller’s single result buffer; the scan
itself is a running total with no per-element allocation.