pub struct ValueMesh<T> { /* private fields */ }Expand description
A mesh of values, one per rank in region.
The internal representation (rep) may be dense or compressed,
but externally the mesh always behaves as a complete mapping from
rank index → value.
§Invariants
- Complete: every rank in
regionhas exactly one value. - Order: iteration and indexing follow the region’s linearization.
Implementations§
Source§impl<T> ValueMesh<T>
impl<T> ValueMesh<T>
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Returns an empty mesh: a 1-dimensional region of length 0.
This differs from a dimensionless (0-D) region, which
represents a single scalar element. A zero-length 1-D region
has no elements at all, making it the natural Default
placeholder for accumulator state initialization.
Source§impl<T: Clone> ValueMesh<T>
impl<T: Clone> ValueMesh<T>
Sourcepub fn from_single(region: Region, s: T) -> Self
pub fn from_single(region: Region, s: T) -> Self
Builds a ValueMesh that assigns the single value s to
every rank in region, without materializing a dense
Vec<T>. The result is stored in compressed (RLE) form as a
single run [0..N).
If region.num_ranks() == 0, the mesh contains no runs (and
an empty table), regardless of s.
Source§impl<T: Clone + Default> ValueMesh<T>
impl<T: Clone + Default> ValueMesh<T>
Sourcepub fn from_default(region: Region) -> Self
pub fn from_default(region: Region) -> Self
Builds a ValueMesh covering the region, filled with
T::default().
Equivalent to [ValueMesh::from_single(region, T::default())].
Source§impl<T: Eq + Hash> ValueMesh<T>
impl<T: Eq + Hash> ValueMesh<T>
Sourcepub fn from_ranges_with_default(
region: Region,
default: T,
ranges: Vec<(Range<usize>, T)>,
) -> Result<Self>
pub fn from_ranges_with_default( region: Region, default: T, ranges: Vec<(Range<usize>, T)>, ) -> Result<Self>
Builds a compressed mesh from a default value and a set of disjoint ranges that override the default.
rangesmay be in any order; they must be non-empty, in-bounds, and non-overlapping.- Unspecified ranks are filled with
default. - Result is stored in RLE form; no dense
Vec<T>is materialized.
Sourcepub fn from_dense(region: Region, values: Vec<T>) -> Result<Self>
pub fn from_dense(region: Region, values: Vec<T>) -> Result<Self>
Builds a ValueMesh from a fully materialized dense vector
of per-rank values, then compresses it into run-length–encoded
form if possible.
This constructor is intended for callers that already have one value per rank (e.g. computed or received data) but wish to store it efficiently.
§Parameters
region: The logical region describing the mesh’s shape and rank order.values: A dense vector of values, one per rank inregion.
§Returns
A ValueMesh whose internal representation is Compressed
if any adjacent elements are equal, or Dense if no
compression was possible.
§Errors
Returns an error if the number of provided values does not
match the number of ranks in region.
§Examples
let region: Region = extent!(n = 5).into();
let mesh = ValueMesh::from_dense(region, vec![1, 1, 2, 2, 3]).unwrap();
// Internally compressed to three runs: [1, 1], [2, 2], [3]Source§impl<T: PartialEq> ValueMesh<T>
impl<T: PartialEq> ValueMesh<T>
Sourcepub fn compress_adjacent_in_place(&mut self)
pub fn compress_adjacent_in_place(&mut self)
Compresses the mesh in place using run-length encoding (RLE).
This method scans the mesh’s dense values, coalescing adjacent
runs of identical elements into a compact [Rep::Compressed]
representation. It replaces the internal storage (rep) with
the compressed form.
§Behavior
- If the mesh is already compressed, this is a no-op.
- If the mesh is dense, it consumes the current
Vec<T>and rebuilds the representation as a run table plus value table. - Only adjacent equal values are merged; non-contiguous duplicates remain distinct.
§Requirements
Tmust implementPartialEq(to detect equal values).
This operation is lossless: expanding the compressed mesh back into a dense vector yields the same sequence of values.
Source§impl<T: Clone + Eq> ValueMesh<T>
impl<T: Clone + Eq> ValueMesh<T>
Sourcepub fn merge_from_overlay(
&mut self,
overlay: ValueOverlay<T>,
) -> Result<(), BuildError>
pub fn merge_from_overlay( &mut self, overlay: ValueOverlay<T>, ) -> Result<(), BuildError>
Merge a sparse overlay into this mesh.
Overlay segments are applied with last-writer-wins
precedence on overlap (identical to RankedValues::merge_from
behavior). The result is stored compressed.
Source§impl<T> ValueMesh<T>
impl<T> ValueMesh<T>
Sourcepub fn compress_adjacent_in_place_by<F>(&mut self, same: F)
pub fn compress_adjacent_in_place_by<F>(&mut self, same: F)
Compresses the mesh in place using a custom equivalence predicate.
This is a generalized form of [compress_adjacent_in_place]
that merges adjacent values according to an arbitrary
predicate same(a, b), rather than relying on PartialEq.
§Behavior
- If the mesh is already compressed, this is a no-op.
- Otherwise, consumes the dense
Vec<T>and replaces it with a run-length encoded (Rep::Compressed) representation, where consecutive elements satisfyingsame(a, b)are coalesced into a single run.
§Requirements
- The predicate must be reflexive and symmetric for correctness.
This operation is lossless: expanding the compressed mesh reproduces the original sequence exactly under the same equivalence.
Trait Implementations§
Source§impl<T> Accumulator for ValueMesh<T>
Accumulates sparse overlay updates into an authoritative mesh.
impl<T> Accumulator for ValueMesh<T>
Accumulates sparse overlay updates into an authoritative mesh.
Lifecycle:
- Mailbox initializes
StateviaDefault(empty mesh). - On the first update, the accumulator clones
self(the template passed toopen_accum_port_opts) intostate. Callers pass a template such asStatusMesh::from_single(region, NotExist). - Each overlay update is merged with right-wins semantics via
merge_from_overlay, and the accumulator emits a full ValueMesh.
The accumulator’s state is a ValueMesh<T> and its updates are
ValueOverlay<T> instances. On each update, the overlay’s
normalized runs are merged into the mesh using
ValueMesh::merge_from_overlay with right-wins semantics.
This enables incremental reduction of sparse updates across distributed reducers without materializing dense data.
Source§type Update = ValueOverlay<T>
type Update = ValueOverlay<T>
Source§fn accumulate(
&self,
state: &mut Self::State,
update: Self::Update,
) -> Result<()>
fn accumulate( &self, state: &mut Self::State, update: Self::Update, ) -> Result<()>
Source§fn reducer_spec(&self) -> Option<ReducerSpec>
fn reducer_spec(&self) -> Option<ReducerSpec>
Source§impl<T> BuildFromRegion<T> for ValueMesh<T>
impl<T> BuildFromRegion<T> for ValueMesh<T>
Source§impl<T> BuildFromRegionIndexed<T> for ValueMesh<T>
impl<T> BuildFromRegionIndexed<T> for ValueMesh<T>
Source§impl<'de, T> Deserialize<'de> for ValueMesh<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for ValueMesh<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T: 'static> Ranked for ValueMesh<T>
impl<T: 'static> Ranked for ValueMesh<T>
Source§fn get(&self, rank: usize) -> Option<&Self::Item>
fn get(&self, rank: usize) -> Option<&Self::Item>
Looks up the value at the given linearized rank.
Works transparently for both dense and compressed representations:
- In the dense case, it simply indexes into the
valuesvector. - In the compressed case, it performs a binary search over run
boundaries to find which run contains the given rank, then
returns the corresponding entry from
table.
Returns None if the rank is out of bounds.
Source§impl<T: Clone + 'static> RankedSliceable for ValueMesh<T>
impl<T: Clone + 'static> RankedSliceable for ValueMesh<T>
impl<T: Eq> Eq for ValueMesh<T>
impl<T> StructuralPartialEq for ValueMesh<T>
Auto Trait Implementations§
impl<T> Freeze for ValueMesh<T>
impl<T> RefUnwindSafe for ValueMesh<T>where
T: RefUnwindSafe,
impl<T> Send for ValueMesh<T>where
T: Send,
impl<T> Sync for ValueMesh<T>where
T: Sync,
impl<T> Unpin for ValueMesh<T>where
T: Unpin,
impl<T> UnwindSafe for ValueMesh<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<A, M> Handler<IndexedErasedUnbound<M>> for A
impl<A, M> Handler<IndexedErasedUnbound<M>> for A
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> MapIntoExt for Twhere
T: Ranked,
impl<T> MapIntoExt for Twhere
T: Ranked,
§impl<T> NoneValue for Twhere
T: Default,
impl<T> NoneValue for Twhere
T: Default,
type NoneType = T
§fn null_value() -> T
fn null_value() -> T
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> QuoteExt for Twhere
T: ?Sized,
impl<T> QuoteExt for Twhere
T: ?Sized,
fn push_quoted<'q, Q, S>(&mut self, _q: Q, s: S)where
Q: QuoteInto<T>,
S: Into<Quotable<'q>>,
Source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
Source§impl<T> ViewExt for Twhere
T: View,
impl<T> ViewExt for Twhere
T: View,
Source§fn range<R>(&self, dim: &str, range: R) -> Result<<T as View>::View, ViewError>
fn range<R>(&self, dim: &str, range: R) -> Result<<T as View>::View, ViewError>
Source§fn group_by(
&self,
dim: &str,
) -> Result<impl Iterator<Item = <T as View>::View>, ViewError>
fn group_by( &self, dim: &str, ) -> Result<impl Iterator<Item = <T as View>::View>, ViewError>
dim. The returned iterator enumerates all groups
as views in the extent of dim to the last dimension of the view. Read more