pub struct IntVecSeqReader<'a, T: Storable, E: Endianness, B: AsRef<[u64]>>where
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64]>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,{ /* private fields */ }
Expand description
A stateful, sequential reader for an IntVec
optimized for forward access.
This reader is created by the seq_reader
method. It maintains an internal cursor corresponding to the last-read
element’s position, making it highly efficient for sequential or
mostly-forward access patterns.
It is a more specialized tool than IntVecReader
.
§Performance
IntVecSeqReader
maintains an internal state of the current decoding position.
When a new get
request is made, it decides whether to:
-
Decode Forward (Fast Path): If the requested index is at or after the current position and within the same sample block, the reader decodes forward from its last position. This avoids a costly seek operation and is the primary optimization.
-
Seek and Decode (Fallback): If the requested index is far away or requires moving backward, the reader falls back to seeking to the nearest sample point and decoding from there, just like
IntVecReader
.
§Examples
use compressed_intvec::variable::{IntVec, UIntVec};
let data: Vec<u32> = (0..100).collect();
let vec: UIntVec<u32> = IntVec::from_slice(&data).unwrap();
// Create a reader optimized for sequential access
let mut seq_reader = vec.seq_reader();
// Accessing indices in increasing order is very efficient
assert_eq!(seq_reader.get(10).unwrap(), Some(10));
assert_eq!(seq_reader.get(15).unwrap(), Some(15)); // Decodes forward from index 10
assert_eq!(seq_reader.get(90).unwrap(), Some(90)); // Jumps to a new sample
Implementations§
Source§impl<'a, T: Storable, E: Endianness, B: AsRef<[u64]>> IntVecSeqReader<'a, T, E, B>where
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64]>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
impl<'a, T: Storable, E: Endianness, B: AsRef<[u64]>> IntVecSeqReader<'a, T, E, B>where
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64]>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
Sourcepub fn get(&mut self, index: usize) -> Result<Option<T>, IntVecError>
pub fn get(&mut self, index: usize) -> Result<Option<T>, IntVecError>
Retrieves the element at index
, or None
if out of bounds.
This method leverages the reader’s internal state to optimize access, especially for sequential reads.
Sourcepub unsafe fn get_unchecked(&mut self, index: usize) -> T
pub unsafe fn get_unchecked(&mut self, index: usize) -> T
Retrieves the element at index
without bounds checking.
§Safety
Calling this method with an out-of-bounds index is undefined behavior.
The caller must ensure that index < self.intvec.len()
.
Auto Trait Implementations§
impl<'a, T, E, B> Freeze for IntVecSeqReader<'a, T, E, B>
impl<'a, T, E, B> RefUnwindSafe for IntVecSeqReader<'a, T, E, B>
impl<'a, T, E, B> Send for IntVecSeqReader<'a, T, E, B>
impl<'a, T, E, B> Sync for IntVecSeqReader<'a, T, E, B>
impl<'a, T, E, B> Unpin for IntVecSeqReader<'a, T, E, B>
impl<'a, T, E, B> UnwindSafe for IntVecSeqReader<'a, T, E, B>
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, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
Source§impl<T> DowncastableFrom<T> for T
impl<T> DowncastableFrom<T> for T
Source§fn downcast_from(value: T) -> T
fn downcast_from(value: T) -> T
Source§impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more