Module iter_mut

Module iter_mut 

Source
Expand description

§Mutable Iterators

This module provides iterators for mutable, sequential access to the elements of a FixedVec.

§Provided Iterators

  • IterMut: An iterator that yields a mutable proxy for each element.
  • ChunksMut: An iterator that yields non-overlapping, mutable slices.

§Examples

§Mutating elements in chunks

The ChunksMut iterator allows for processing a vector in mutable, non-overlapping chunks.

use compressed_intvec::fixed::{FixedVec, UFixedVec, BitWidth};

let data: Vec<u32> = (0..100).collect();
let mut vec: UFixedVec<u32> = FixedVec::builder().bit_width(BitWidth::Explicit(8)).build(&data).unwrap();

// Process each chunk sequentially.
for mut chunk in vec.chunks_mut(10) {
    // Each chunk is a `FixedVecSlice` that can be mutated.
    for i in 0..chunk.len() {
        if let Some(mut proxy) = chunk.at_mut(i) {
            *proxy *= 2;
        }
    }
}

assert_eq!(vec.get(10), Some(20));
assert_eq!(vec.get(99), Some(198));

Structs§

ChunksMut
An iterator over non-overlapping, mutable chunks of a FixedVec.
IterMut
A mutable iterator over the elements of a FixedVec.
IterMutUnchecked
An unchecked mutable iterator over the elements of a FixedVec.