pub struct SeqVecBuilder<T: Storable, E: Endianness> { /* private fields */ }Expand description
A builder for creating a SeqVec from a collection of sequences.
This builder is the primary entry point for constructing a compressed sequence vector when the sequences are already available in memory. It allows configuration of the compression codec.
The builder always produces an owned SeqVec<T, E, Vec<u64>>.
§Construction Strategy
When the codec is Codec::Auto or requires parameter
estimation (e.g., Rice { log2_b: None }), the builder performs a two-pass
construction:
- Analysis pass: Collects all elements to determine the optimal codec.
- Encoding pass: Compresses the data using the selected codec.
When a fully-specified codec is provided (e.g., Gamma, Delta,
Zeta { k: Some(3) }), the builder performs single-pass construction,
avoiding the temporary allocation of all elements.
§Examples
use compressed_intvec::seq::{SeqVec, LESeqVec, Codec};
let sequences: &[&[u32]] = &[&[1, 2, 3], &[10, 20], &[100]];
// Automatic codec selection (two-pass)
let vec_auto: LESeqVec<u32> = SeqVec::builder()
.codec(Codec::Auto)
.build(sequences)?;
// Explicit codec (single-pass, more efficient)
let vec_gamma: LESeqVec<u32> = SeqVec::builder()
.codec(Codec::Gamma)
.build(sequences)?;Implementations§
Source§impl<T: Storable, E: Endianness> SeqVecBuilder<T, E>
impl<T: Storable, E: Endianness> SeqVecBuilder<T, E>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new builder with default settings.
The default codec is Codec::Auto, which analyzes the
data to select the best codec.
Sourcepub fn codec(self, codec_spec: Codec) -> Self
pub fn codec(self, codec_spec: Codec) -> Self
Sets the compression codec to use.
For the available codecs, see Codec.
Sourcepub fn store_lengths(self, store: bool) -> Self
pub fn store_lengths(self, store: bool) -> Self
Enables or disables storing explicit sequence lengths.
When enabled, the builder stores a compact FixedVec of per-sequence
lengths. This allows O(1) length queries and enables faster decoding
paths that avoid end-bit checks.
The default is false to minimize memory usage.
Sourcepub fn build<S: AsRef<[T]>>(
self,
sequences: &[S],
) -> Result<SeqVec<T, E, Vec<u64>>, SeqVecError>where
T: 'static,
BufBitWriter<E, MemWordWriterVec<u64, Vec<u64>>>: BitWrite<E, Error = Infallible> + CodesWrite<E>,
pub fn build<S: AsRef<[T]>>(
self,
sequences: &[S],
) -> Result<SeqVec<T, E, Vec<u64>>, SeqVecError>where
T: 'static,
BufBitWriter<E, MemWordWriterVec<u64, Vec<u64>>>: BitWrite<E, Error = Infallible> + CodesWrite<E>,
Builds the SeqVec from a slice of sequences.
Each element represents a sequence to compress and store. Empty sequences are supported.
§Type Requirements
The sequences can be any type that implements AsRef<[T]>, such as
&[T], Vec<T>, or Box<[T]>.
§Arguments
sequences- A slice of sequences to compress. Each sequence is accessed viaAsRef<[T]>.
§Errors
Returns a SeqVecError if:
- Codec resolution fails.
- An I/O error occurs during encoding.
§Examples
use compressed_intvec::seq::{SeqVec, LESeqVec};
// From slice of slices
let data: &[&[u32]] = &[&[1, 2], &[3, 4, 5]];
let vec: LESeqVec<u32> = SeqVec::builder().build(data)?;
// From Vec of Vecs
let data: Vec<Vec<u32>> = vec![vec![1, 2], vec![3, 4, 5]];
let vec: LESeqVec<u32> = SeqVec::builder().build(&data)?;Trait Implementations§
Source§impl<T: Clone + Storable, E: Clone + Endianness> Clone for SeqVecBuilder<T, E>
impl<T: Clone + Storable, E: Clone + Endianness> Clone for SeqVecBuilder<T, E>
Source§fn clone(&self) -> SeqVecBuilder<T, E>
fn clone(&self) -> SeqVecBuilder<T, E>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Debug + Storable, E: Debug + Endianness> Debug for SeqVecBuilder<T, E>
impl<T: Debug + Storable, E: Debug + Endianness> Debug for SeqVecBuilder<T, E>
Source§impl<T: Storable, E: Endianness> Default for SeqVecBuilder<T, E>
impl<T: Storable, E: Endianness> Default for SeqVecBuilder<T, E>
Auto Trait Implementations§
impl<T, E> Freeze for SeqVecBuilder<T, E>
impl<T, E> RefUnwindSafe for SeqVecBuilder<T, E>where
T: RefUnwindSafe,
E: RefUnwindSafe,
impl<T, E> Send for SeqVecBuilder<T, E>where
T: Send,
impl<T, E> Sync for SeqVecBuilder<T, E>where
T: Sync,
impl<T, E> Unpin for SeqVecBuilder<T, E>
impl<T, E> UnsafeUnpin for SeqVecBuilder<T, E>
impl<T, E> UnwindSafe for SeqVecBuilder<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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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