pub struct VarVecSeqReader<'a, T: Storable, E: Endianness, B: AsRef<[u64]>>where
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64], true>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,{ /* private fields */ }Expand description
A stateful, sequential reader for an VarVec 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 VarVecReader.
§Performance
VarVecSeqReader 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
VarVecReader.
§Examples
use compressed_intvec::variable::{VarVec, UVarVec};
let data: Vec<u32> = (0..100).collect();
let vec: UVarVec<u32> = VarVec::from_slice(&data)?;
// 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)?, Some(10));
assert_eq!(seq_reader.get(15)?, Some(15)); // Decodes forward from index 10
assert_eq!(seq_reader.get(90)?, Some(90)); // Jumps to a new sampleImplementations§
Source§impl<'a, T: Storable, E: Endianness, B: AsRef<[u64]>> VarVecSeqReader<'a, T, E, B>where
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64], true>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
impl<'a, T: Storable, E: Endianness, B: AsRef<[u64]>> VarVecSeqReader<'a, T, E, B>where
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64], true>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
Sourcepub fn get(&mut self, index: usize) -> Result<Option<T>, VarVecError>
pub fn get(&mut self, index: usize) -> Result<Option<T>, VarVecError>
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().
Trait Implementations§
Source§impl<T: Storable, E: Endianness, B: AsRef<[u64]>> Debug for VarVecSeqReader<'_, T, E, B>where
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64], true>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
impl<T: Storable, E: Endianness, B: AsRef<[u64]>> Debug for VarVecSeqReader<'_, T, E, B>where
for<'b> BufBitReader<E, MemWordReader<u64, &'b [u64], true>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
Auto Trait Implementations§
impl<'a, T, E, B> Freeze for VarVecSeqReader<'a, T, E, B>
impl<'a, T, E, B> RefUnwindSafe for VarVecSeqReader<'a, T, E, B>
impl<'a, T, E, B> Send for VarVecSeqReader<'a, T, E, B>
impl<'a, T, E, B> Sync for VarVecSeqReader<'a, T, E, B>
impl<'a, T, E, B> Unpin for VarVecSeqReader<'a, T, E, B>where
E: Unpin,
impl<'a, T, E, B> UnsafeUnpin for VarVecSeqReader<'a, T, E, B>
impl<'a, T, E, B> UnwindSafe for VarVecSeqReader<'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