tiny.reducer.Capacity
Defined in bytes.capacity.
Workspace layout derived from the caller's limits, sized so that a run in steady state needs no further allocation.
API (5)
Actions
Public operations.
derive: Works out the memory a workspace needs to reduce inputs up tolimits.max_input_bytes.
Fields and members
Public fields and members.
Source
Source: lib/reducer/src/bytes/capacity.zig:56
zig
/// Workspace layout derived from the caller's limits, sized so that a run in/// steady state needs no further allocation.pub const Capacity = struct { /// Caller's limits that this capacity was derived from. limits: Limits, /// Byte offset in the backing allocation where the scratch lane starts. It /// equals `limits.max_input_bytes` exactly. candidate_offset: usize, /// Greatest length in bytes any candidate takes, which is $\max(N - 1, 0)$. candidate_bytes: usize, /// Total the combined allocation needs, which is /// $\text{candidate\_offset} + \text{candidate\_bytes}$. storage_bytes: usize, /// Works out the memory a workspace needs to reduce inputs up to /// `limits.max_input_bytes`. It computes $N + \max(N - 1, 0)$, taking the /// scratch lane's length with saturating subtraction and the total with /// checked addition. It produces the arithmetic layout alone and calls no /// allocator. /// /// ## Errors /// It returns `DeriveError.CapacityOverflow` when the combined requirement /// exceeds `std.math.maxInt(usize)`. pub fn derive(limits: Limits) DeriveError!Capacity { const candidate_bytes = limits.max_input_bytes -| 1; const capacity = Capacity{ .limits = limits, .candidate_offset = limits.max_input_bytes, .candidate_bytes = candidate_bytes, .storage_bytes = std.math.add( usize, limits.max_input_bytes, candidate_bytes, ) catch return error.CapacityOverflow, }; std.debug.assert(capacity.candidate_offset == limits.max_input_bytes); std.debug.assert(capacity.candidate_bytes <= limits.max_input_bytes); std.debug.assert(capacity.storage_bytes >= limits.max_input_bytes); std.debug.assert( capacity.candidate_offset + capacity.candidate_bytes == capacity.storage_bytes, ); return capacity; }};Source: lib/reducer/src/root.zig:317
zig
/// Workspace layout derived from the caller's limits, sized so that a run in/// steady state needs no further allocation.pub const Capacity = bytes.Capacity;Also reachable as
Audit
| Definitions | 2 |
|---|---|
| Public names | 6 |
| Members | 4 |
| Version | 26.7.0 |
| Revision | daab053ee433 |