pub struct WindowedIterState<I, T> {
len: usize,
iter: RefCell<Option<I>>,
consumed: RefCell<usize>,
window: RefCell<Vec<T>>,
window_start: RefCell<usize>,
window_size: usize,
materialized: OnceLock<Vec<T>>,
}Expand description
Core state for windowed iterator-backed ALTREP vectors.
Like super::IterState, but only keeps a sliding window of elements in memory.
Sequential access within the window is O(1). Access outside the window
materializes the entire vector (falling back to full caching).
This is useful for large iterators where only a small region is accessed at a time (e.g., streaming data processed in order).
§Type Parameters
I: The iterator typeT: The element type produced by the iterator
Fields§
§len: usize§iter: RefCell<Option<I>>§consumed: RefCell<usize>§window: RefCell<Vec<T>>§window_start: RefCell<usize>§window_size: usize§materialized: OnceLock<Vec<T>>Implementations§
Source§impl<I, T> WindowedIterState<I, T>
impl<I, T> WindowedIterState<I, T>
Sourcepub fn new(iter: I, len: usize, window_size: usize) -> Self
pub fn new(iter: I, len: usize, window_size: usize) -> Self
Create a new windowed iterator state.
Sourcepub fn get_element(&self, i: usize) -> Option<T>
pub fn get_element(&self, i: usize) -> Option<T>
Get element at index i.
Sourcefn advance_to(&self, i: usize)
fn advance_to(&self, i: usize)
Advance the iterator to fill a window containing index i.
Sourcepub fn materialize_all(&self) -> &[T]
pub fn materialize_all(&self) -> &[T]
Materialize all elements.
Sourcepub fn as_materialized(&self) -> Option<&[T]>
pub fn as_materialized(&self) -> Option<&[T]>
Get materialized slice if available.
Source§impl<I, T> WindowedIterState<I, T>where
I: ExactSizeIterator<Item = T>,
T: Copy,
impl<I, T> WindowedIterState<I, T>where
I: ExactSizeIterator<Item = T>,
T: Copy,
Sourcepub fn from_exact_size(iter: I, window_size: usize) -> Self
pub fn from_exact_size(iter: I, window_size: usize) -> Self
Create from an ExactSizeIterator.
Auto Trait Implementations§
impl<I, T> !Freeze for WindowedIterState<I, T>
impl<I, T> !RefUnwindSafe for WindowedIterState<I, T>
impl<I, T> Send for WindowedIterState<I, T>
impl<I, T> !Sync for WindowedIterState<I, T>
impl<I, T> Unpin for WindowedIterState<I, T>
impl<I, T> UnsafeUnpin for WindowedIterState<I, T>where
I: UnsafeUnpin,
impl<I, T> UnwindSafe for WindowedIterState<I, T>where
I: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
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
Mutably borrows from an owned value. Read more