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
Source§impl<T> SizeEq<MaybeUninit<T>> for T
impl<T> SizeEq<MaybeUninit<T>> for T
type CastFrom = CastSizedExact
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreimpl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> InvariantsEq<ManuallyDrop<T>> for Twhere
T: ?Sized,
impl<T> InvariantsEq<T> for Twhere
T: ?Sized,
impl<T> InvariantsEq<Unalign<T>> for T
impl<T> InvariantsEq<Wrapping<T>> for T
impl<Src, Dst, A, SV, DV, R> MutationCompatible<Src, A, SV, DV, (BecauseRead, R)> for Dst
impl<Src, Dst, A, SV, DV> MutationCompatible<Src, A, SV, DV, BecauseInvariantsEq> for Dstwhere
A: Aliasing,
SV: Validity,
DV: Validity,
Src: TransmuteFrom<Dst, DV, SV> + ?Sized,
Dst: TransmuteFrom<Src, SV, DV> + InvariantsEq<Src> + ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<Cell<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<ManuallyDrop<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<ReadOnly<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<Src, Dst> TransmuteFrom<Src, Initialized, Initialized> for Dst
impl<Src, Dst, V> TransmuteFrom<Src, V, Uninit> for Dst
impl<Src, Dst> TransmuteFrom<Src, Valid, Initialized> for Dst
impl<T> TransmuteFrom<Unalign<T>, Valid, Valid> for T
impl<T> TransmuteFrom<UnsafeCell<T>, Valid, Valid> for Twhere
T: ?Sized,
impl<T> TransmuteFrom<Wrapping<T>, Valid, Valid> for T
impl<Src, Dst, A, SV, DV, C, R> TransmuteFromPtr<Src, A, SV, DV, C, R> for Dstwhere
A: Aliasing,
SV: Validity,
DV: Validity,
C: CastExact<Src, Dst>,
Dst: TransmuteFrom<Src, SV, DV> + TryTransmuteFromPtr<Src, A, SV, DV, C, R> + ?Sized,
Src: ?Sized,
impl<Src, Dst, SV, DV, A, C, R> TryTransmuteFromPtr<Src, A, SV, DV, C, (BecauseMutationCompatible, R)> for Dstwhere
A: Aliasing,
SV: Validity,
DV: Validity,
Src: TransmuteFrom<Dst, DV, SV> + ?Sized,
Dst: MutationCompatible<Src, A, SV, DV, R> + ?Sized,
C: CastExact<Src, Dst>,
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.