pub struct IntVecBuilder<T: Storable, E: Endianness> { /* private fields */ }Expand description
A builder for creating an IntVec 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 IntVec<T, E, Vec<u64>>. It is obtained
by calling IntVec::builder.
Implementations§
Source§impl<T: Storable, E: Endianness> IntVecBuilder<T, E>
impl<T: Storable, E: Endianness> IntVecBuilder<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: VariableCodecSpec) -> Self
pub fn codec(self, codec_spec: VariableCodecSpec) -> Self
Sets the compression codec to use.
The choice of codec can significantly impact the compression ratio.
By default, this is VariableCodecSpec::Auto, which analyzes the data
to select the best codec.
Sourcepub fn build(self, input: &[T]) -> Result<IntVec<T, E, Vec<u64>>, IntVecError>where
BufBitWriter<E, MemWordWriterVec<u64, Vec<u64>>>: BitWrite<E, Error = Infallible> + CodesWrite<E>,
pub fn build(self, input: &[T]) -> Result<IntVec<T, E, Vec<u64>>, IntVecError>where
BufBitWriter<E, MemWordWriterVec<u64, Vec<u64>>>: BitWrite<E, Error = Infallible> + CodesWrite<E>,
Builds the IntVec from a slice of data, consuming the builder.
This method performs the compression and builds the sampling table.
§Errors
Returns an IntVecError if the parameters are invalid (e.g., k=0) or
if an error occurs during compression.
§Examples
use compressed_intvec::variable::{IntVec, SIntVec, VariableCodecSpec};
let data: &[i16] = &[-100, 0, 50, -2, 1000];
let vec: SIntVec<i16> = IntVec::builder()
.k(2) // Smaller `k` for faster access
.codec(VariableCodecSpec::Delta) // Explicitly choose Delta coding
.build(data)
.unwrap();
assert_eq!(vec.len(), 5);
assert_eq!(vec.get(0), Some(-100));Trait Implementations§
Auto Trait Implementations§
impl<T, E> Freeze for IntVecBuilder<T, E>
impl<T, E> RefUnwindSafe for IntVecBuilder<T, E>where
T: RefUnwindSafe,
E: RefUnwindSafe,
impl<T, E> Send for IntVecBuilder<T, E>where
T: Send,
impl<T, E> Sync for IntVecBuilder<T, E>where
T: Sync,
impl<T, E> Unpin for IntVecBuilder<T, E>
impl<T, E> UnwindSafe for IntVecBuilder<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