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.
Access within the window is O(1), and reading past it slides the window
forward. The iterator cannot be rewound, so reading an element that has left
the window is an error. Use super::IterState when R may read elements
again or out of order.
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.
§Panics
If elements have already left the window, or if the iterator ends before the declared length.
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> !Sync for WindowedIterState<I, T>
impl<I, T> Send for WindowedIterState<I, T>
impl<I, T> Unpin for WindowedIterState<I, T>
impl<I, T> UnsafeUnpin for WindowedIterState<I, T>
impl<I, T> UnwindSafe for WindowedIterState<I, T>
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> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§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 moreLayout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.