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
FixedVecIter
: A stateful, bidirectional iterator over the elements of a borrowedFixedVec
.FixedVecIntoIter
: A consuming, bidirectional iterator that takes ownership of aFixedVec
.FixedVecSliceIter
: A stateful, bidirectional iterator over the elements of aFixedVecSlice
.Chunks
: An iterator that yields non-overlapping, immutable slices (FixedVecSlice
).Windows
: An iterator that yields overlapping, immutable slices (FixedVecSlice
).FixedVecUncheckedIter
: Anunsafe
bidirectional iterator that omits bounds checks for maximum performance.
§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
. - Fixed
VecInto Iter - An iterator that consumes an owned
FixedVec
and yields its elements. - Fixed
VecIter - An iterator over the elements of a borrowed
FixedVec
. - Fixed
VecSlice Iter - An iterator over the elements of a
FixedVecSlice
. - Fixed
VecUnchecked Iter - An unchecked iterator over the elements of a
FixedVec
. - Windows
- An iterator over overlapping sub-slices of a
FixedVec
.