pub struct IntVecReader<'a, E: Endianness>where
for<'b> BufBitReader<E, MemWordReader<u64, &'b Vec<u64>>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,{ /* private fields */ }
Expand description
A stateful reader for an IntVec
that provides fast random access.
This reader is created by the IntVec::reader
method. It maintains an
internal, reusable bitstream reader, which makes it highly efficient for
performing multiple random lookups, especially when the access pattern is
not known in advance (e.g., indices are generated on-the-fly in a loop).
By reusing the same underlying reader, it amortizes the setup cost across
many get
operations.
§When to use IntVecReader
- When you need to perform multiple lookups and the indices are determined dynamically.
- When the next lookup index might depend on the result of the previous one.
For batch lookups where all indices are known beforehand, using
IntVec::get_many
is still preferable as it can perform global optimizations
like sorting the indices. There is a parallel version of this method, IntVec::par_get_many
.
§Example
use compressed_intvec::prelude::*;
let data: &[u64] = &[10, 20, 30, 40, 50];
let intvec = LEIntVec::builder(data).build().unwrap();
// Create a reusable reader from the IntVec.
let mut reader = intvec.reader();
// Perform multiple lookups. The reader efficiently handles seeks.
assert_eq!(reader.get(3).unwrap(), Some(40));
assert_eq!(reader.get(1).unwrap(), Some(20));
assert_eq!(reader.get(0).unwrap(), Some(10));
Implementations§
Source§impl<'a, E: Endianness> IntVecReader<'a, E>where
for<'b> BufBitReader<E, MemWordReader<u64, &'b Vec<u64>>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
impl<'a, E: Endianness> IntVecReader<'a, E>where
for<'b> BufBitReader<E, MemWordReader<u64, &'b Vec<u64>>, DefaultReadParams>: BitRead<E, Error = Infallible> + CodesRead<E> + BitSeek<Error = Infallible>,
Sourcepub fn get(&mut self, index: usize) -> Result<Option<u64>, IntVecError>
pub fn get(&mut self, index: usize) -> Result<Option<u64>, IntVecError>
Retrieves the element at the specified index using the reusable reader.
This method leverages the stateful nature of the reader to perform efficient random access.
§Implementation Notes
The access strategy is identical to that of IntVec::get
, but because
this method operates on a long-lived reader instance, it avoids the setup
overhead associated with calling IntVec::get
repeatedly.
- For fixed-width integer encoding: Access is O(1). The bit position is calculated and the reader seeks directly to it.
- For variable-length, bit-level codes: The reader seeks to the nearest preceding sample point and decodes sequentially from there.
§Example
use compressed_intvec::prelude::*;
let data: &[u64] = &[10, 20, 30, 40, 50];
let intvec = LEIntVec::builder(data).build().unwrap();
let mut reader = intvec.reader();
assert_eq!(reader.get(2).unwrap(), Some(30));
assert_eq!(reader.get(10).unwrap(), None); // Out of bounds
Auto Trait Implementations§
impl<'a, E> Freeze for IntVecReader<'a, E>
impl<'a, E> RefUnwindSafe for IntVecReader<'a, E>where
E: RefUnwindSafe,
impl<'a, E> Send for IntVecReader<'a, E>
impl<'a, E> Sync for IntVecReader<'a, E>
impl<'a, E> Unpin for IntVecReader<'a, E>where
E: Unpin,
impl<'a, E> UnwindSafe for IntVecReader<'a, E>where
E: RefUnwindSafe + 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, 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