Module iter

Module iter 

Source
Expand description

§FixedVec Iterators

This module provides iterators for sequential access to the elements of a FixedVec. The iterators decode values on the fly without allocating an intermediate buffer, making them efficient for processing large datasets.

The core iterators (FixedVecIter, FixedVecSliceIter) are stateful and employ a bit-windowing technique. They decode values on the fly without allocating an intermediate buffer. They support both forward and reverse iteration.

§Provided Iterators

§Examples

§Iterating over elements

use compressed_intvec::fixed::{FixedVec, SFixedVec};

let data: &[i16] = &[-100, 0, 100, 200];
let vec: SFixedVec<i16> = FixedVec::builder().build(data).unwrap();

let mut sum = 0;
for value in vec.iter() {
    sum += value;
}

assert_eq!(sum, 200);

§Bidirectional Iteration

The main iterators implement DoubleEndedIterator, allowing for traversal from both ends of the sequence.

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

let vec: UFixedVec<u8> = (0..=5u8).collect();
let mut iter = vec.iter();

assert_eq!(iter.next(), Some(0));
assert_eq!(iter.next_back(), Some(5));
assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next_back(), Some(4));

// The iterator correctly tracks its remaining length.
assert_eq!(iter.len(), 2);

assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), None);

§Iterating over a Slice

You can also create an iterator over a zero-copy slice of a vector.

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

let vec: UFixedVec<u32> = (0..100u32).collect();

// Create a slice containing elements from index 20 to 29.
let slice = vec.slice(20, 10).unwrap();
assert_eq!(slice.len(), 10);

// The slice iterator will yield the elements from the slice.
let collected: Vec<u32> = slice.iter().collect();
let expected: Vec<u32> = (20..30).collect();

assert_eq!(collected, expected);

Structs§

Chunks
An iterator over non-overlapping, immutable chunks of a FixedVec.
FixedVecIntoIter
An iterator that consumes an owned FixedVec and yields its elements.
FixedVecIter
An iterator over the elements of a borrowed FixedVec.
FixedVecSliceIter
An iterator over the elements of a FixedVecSlice.
FixedVecUncheckedIter
An unchecked iterator over the elements of a FixedVec.
Windows
An iterator over overlapping sub-slices of a FixedVec.