Skip to main content

apply_participation_iter

Function apply_participation_iter 

Source
pub fn apply_participation_iter<T: ListMutTarget<u8>>(
    target: &mut T,
    delta: &ArchivedParticipationDiff,
) -> Result<(), Error>
Expand description

Applies a sparse participation delta to a mutable collection in place.

This API is intended for consensus clients whose participation flags are stored in tree-backed or otherwise non-contiguous structures.

The destination collection is updated according to the sparse entries in delta. Each encoded index gap identifies the next modified entry, whose value is replaced with the corresponding entry from new_values. Values in extension are then appended to the destination.

ParticipationDiff::AllZeros is not supported by this generic API because crate::ListMutTarget does not provide an operation for clearing or resizing an existing collection. Callers should use apply_participation when they need to support that representation.

§Errors

Returns Error::InvalidDelta if the supplied delta is not a sparse representation, if the number of encoded indices does not match the number of replacement values, if an encoded index cannot be represented as a usize, if an index falls outside the destination collection, or if the destination collection cannot provide the required element.

Returns Error::MalformedDelta if the sparse index payload contains an invalid or truncated varint.

§Complexity

O(m + e) time and O(1) additional working space, excluding allocations performed by the destination collection when it grows.

Here m is the number of modified entries and e is the number of appended entries.