pub struct VarVecBuilder<T: Storable, E: Endianness> { /* private fields */ }Expand description
A builder for creating an VarVec from a slice of integers.
This builder is the primary entry point for constructing a compressed vector
when the data is already available in memory. It allows for detailed
configuration of the sampling rate (k) and the compression codec.
This builder always produces an owned VarVec. It is obtained
by calling VarVec::builder.
Implementations§
Source§impl<T: Storable, E: Endianness> VarVecBuilder<T, E>
impl<T: Storable, E: Endianness> VarVecBuilder<T, E>
Sourcepub fn k(self, k: usize) -> Self
pub fn k(self, k: usize) -> Self
Sets the sampling rate k for random access.
The sampling rate determines how many elements are stored between each
sample point. A smaller k results in faster random access but uses
more memory for the sampling table. See the module-level documentation
for a detailed explanation.
§Panics
The build method will return an error if k is 0.
Sourcepub fn codec(self, codec_spec: Codec) -> Self
pub fn codec(self, codec_spec: Codec) -> Self
Sets the compression codec to use.
The choice of codec can significantly impact the compression ratio.
By default, this is Codec::Auto, which analyzes the data
to select the best codec.
Sourcepub fn build(self, input: &[T]) -> Result<VarVec<T, E, Vec<u64>>, VarVecError>where
BufBitWriter<E, MemWordWriterVec<u64, Vec<u64>>>: BitWrite<E, Error = Infallible> + CodesWrite<E>,
pub fn build(self, input: &[T]) -> Result<VarVec<T, E, Vec<u64>>, VarVecError>where
BufBitWriter<E, MemWordWriterVec<u64, Vec<u64>>>: BitWrite<E, Error = Infallible> + CodesWrite<E>,
Builds the VarVec from a slice of data, consuming the builder.
This method performs the compression and builds the sampling table.
§Errors
Returns an VarVecError if the parameters are invalid (e.g., k=0) or
if an error occurs during compression.
§Examples
use compressed_intvec::variable::{VarVec, SVarVec, Codec};
let data: &[i16] = &[-100, 0, 50, -2, 1000];
let vec: SVarVec<i16> = VarVec::builder()
.k(2) // Smaller `k` for faster access
.codec(Codec::Delta) // Explicitly choose Delta coding
.build(data)?;
assert_eq!(vec.len(), 5);
assert_eq!(vec.get(0), Some(-100));Trait Implementations§
Auto Trait Implementations§
impl<T, E> Freeze for VarVecBuilder<T, E>
impl<T, E> RefUnwindSafe for VarVecBuilder<T, E>where
T: RefUnwindSafe,
E: RefUnwindSafe,
impl<T, E> Send for VarVecBuilder<T, E>where
T: Send,
impl<T, E> Sync for VarVecBuilder<T, E>where
T: Sync,
impl<T, E> Unpin for VarVecBuilder<T, E>
impl<T, E> UnsafeUnpin for VarVecBuilder<T, E>
impl<T, E> UnwindSafe for VarVecBuilder<T, E>where
T: UnwindSafe,
E: 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