pub struct IntVec<E: Endianness, W: BitWrite<E>, C: Codec<E, W>> { /* private fields */ }
Expand description
A compressed vector of integers.
The IntVec
stores values in a compressed bitstream along with sample offsets for
fast random access. The type is generic over an endianness (E
) and codec (C
).
§Type Parameters
E
: Endianness marker (e.g.BE
orLE
).C
: The codec used for compression. Must implementCodec<E, MyBitWrite<E>, MyBitRead<E>>
.
§Fields
data
: The compressed bitstream data.samples
: Offsets (in bits) intodata
for every k-th value, used to jump-start decoding.k
: The sampling period.len
: The total number of integers stored.codec_param
: Extra parameters forC
.
§Examples
use compressed_intvec::intvec::BEIntVec;
use compressed_intvec::codecs::GammaCodec;
// Create a compressed vector using a codec without extra parameters.
let input = vec![1, 2, 3, 4, 5];
let intvec = BEIntVec::<GammaCodec>::from(&input, 2).unwrap();
let value = intvec.get(3);
assert_eq!(value, 4);
assert_eq!(intvec.len(), 5);
Implementations§
Source§impl<C: Codec<BE, BufBitWriter<BE, MemWordWriterVec<u64, Vec<u64>>>>> IntVec<BigEndian, BufBitWriter<BigEndian, MemWordWriterVec<u64, Vec<u64>>>, C>
impl<C: Codec<BE, BufBitWriter<BE, MemWordWriterVec<u64, Vec<u64>>>>> IntVec<BigEndian, BufBitWriter<BigEndian, MemWordWriterVec<u64, Vec<u64>>>, C>
Sourcepub fn from_with_param(
input: &[u64],
k: usize,
codec_param: C::Params,
) -> Result<Self, Box<dyn Error>>
pub fn from_with_param( input: &[u64], k: usize, codec_param: C::Params, ) -> Result<Self, Box<dyn Error>>
Creates a new BEIntVec
from a vector of unsigned 64-bit integers.
Values are encoded with the specified codec parameter.
§Arguments
input
: The values to be compressed.k
: The sampling rate (every k-th value is stored as a sample).codec_param
: Parameters for the codec.
§Examples
use compressed_intvec::intvec::BEIntVec;
use compressed_intvec::codecs::ExpGolombCodec;
let input = vec![1, 5, 3, 1991, 42];
let intvec = BEIntVec::<ExpGolombCodec>::from_with_param(&input, 2, 3).unwrap();
let value = intvec.get(3);
assert_eq!(value, 1991);
Sourcepub fn get(&self, index: usize) -> u64
pub fn get(&self, index: usize) -> u64
Retrieves the value at the given index.
Panics if the index is out of bounds.
§Examples
use compressed_intvec::intvec::BEIntVec;
use compressed_intvec::codecs::GammaCodec;
let input = vec![1, 5, 3, 12, 42];
let intvec = BEIntVec::<GammaCodec>::from(&input, 2).unwrap();
let value = intvec.get(3);
assert_eq!(value, 12);
Sourcepub fn into_vec(self) -> Vec<u64>
pub fn into_vec(self) -> Vec<u64>
Returns the original vector of integers.
This operation is expensive as it requires decoding the entire bitstream.
§Examples
use compressed_intvec::intvec::BEIntVec;
use compressed_intvec::codecs::GammaCodec;
let input = vec![43, 12, 5, 1991, 42];
let intvec = BEIntVec::<GammaCodec>::from(&input, 2).unwrap();
let values = intvec.into_vec();
assert_eq!(values, input);
Sourcepub fn iter(&self) -> BEIntVecIter<'_, C> ⓘ
pub fn iter(&self) -> BEIntVecIter<'_, C> ⓘ
Returns an iterator over the decompressed integer values stored in this compressed vector.
The iterator decodes values on the fly and does not modify the underlying data.
§Example
use compressed_intvec::intvec::BEIntVec;
use compressed_intvec::codecs::GammaCodec;
let input = vec![1, 5, 3, 12, 42];
let intvec = BEIntVec::<GammaCodec>::from(&input, 2).unwrap();
// Iterate over the vector and print each value.
for (i, value) in intvec.iter().enumerate() {
assert_eq!(value, input[i]);
}
Sourcepub fn limbs(&self) -> Vec<u64>
pub fn limbs(&self) -> Vec<u64>
Returns a clone of the internal bitstream data as a vector of 64-bit unsigned integers.
This can be used for debugging or low-level operations where access to the raw compressed limb data is required.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of integers stored in the compressed vector.
This value represents the total count of decompressed integers.
Sourcepub fn get_sampling_rate(&self) -> usize
pub fn get_sampling_rate(&self) -> usize
Returns the sampling rate used by the compressed vector.
Sourcepub fn get_samples(&self) -> Vec<usize>
pub fn get_samples(&self) -> Vec<usize>
Returns the codec parameter used by the compressed vector.
Source§impl<C: Codec<BE, BufBitWriter<BE, MemWordWriterVec<u64, Vec<u64>>>, Params = ()>> IntVec<BigEndian, BufBitWriter<BigEndian, MemWordWriterVec<u64, Vec<u64>>>, C>
Convenience constructor for codecs with no extra runtime parameter.
impl<C: Codec<BE, BufBitWriter<BE, MemWordWriterVec<u64, Vec<u64>>>, Params = ()>> IntVec<BigEndian, BufBitWriter<BigEndian, MemWordWriterVec<u64, Vec<u64>>>, C>
Convenience constructor for codecs with no extra runtime parameter.
Source§impl<C> IntVec<LittleEndian, BufBitWriter<LittleEndian, MemWordWriterVec<u64, Vec<u64>>>, C>
impl<C> IntVec<LittleEndian, BufBitWriter<LittleEndian, MemWordWriterVec<u64, Vec<u64>>>, C>
Sourcepub fn from_with_param(
input: &[u64],
k: usize,
codec_param: C::Params,
) -> Result<Self, Box<dyn Error>>
pub fn from_with_param( input: &[u64], k: usize, codec_param: C::Params, ) -> Result<Self, Box<dyn Error>>
Creates a new LEIntVec
from a vector of unsigned 64-bit integers.
Values are encoded with the specified codec parameter.
§Arguments
input
: The values to be compressed.k
: The sampling rate (every k-th value is stored as a sample).codec_param
: Parameters for the codec.
§Examples
use compressed_intvec::intvec::LEIntVec;
use compressed_intvec::codecs::ExpGolombCodec;
let input = vec![1, 5, 3, 1991, 42];
let intvec = LEIntVec::<ExpGolombCodec>::from_with_param(&input, 2, 3).unwrap();
let value = intvec.get(3);
assert_eq!(value, 1991);
Sourcepub fn get(&self, index: usize) -> u64
pub fn get(&self, index: usize) -> u64
Retrieves the value at the given index.
Returns None
if the index is out of bounds.
§Examples
use compressed_intvec::intvec::LEIntVec;
use compressed_intvec::codecs::GammaCodec;
let input = vec![1, 5, 3, 1991, 42];
let intvec = LEIntVec::<GammaCodec>::from(&input, 2).unwrap();
let value = intvec.get(3);
assert_eq!(value, 1991);
Sourcepub fn into_vec(self) -> Vec<u64>
pub fn into_vec(self) -> Vec<u64>
Returns the original vector of integers.
This operation is expensive as it requires decoding the entire bitstream.
§Examples
use compressed_intvec::intvec::LEIntVec;
use compressed_intvec::codecs::GammaCodec;
let input = vec![43, 12, 5, 1991, 42];
let intvec = LEIntVec::<GammaCodec>::from(&input, 2).unwrap();
let values = intvec.into_vec();
assert_eq!(values, input);
Sourcepub fn iter(&self) -> LEIntVecIter<'_, C> ⓘ
pub fn iter(&self) -> LEIntVecIter<'_, C> ⓘ
Returns an iterator over the values stored in the vector.
Sourcepub fn limbs(&self) -> Vec<u64>
pub fn limbs(&self) -> Vec<u64>
Returns a clone of the internal bitstream data as a vector of 64-bit unsigned integers.
This can be used for debugging or low-level operations where access to the raw compressed limb data is required.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of integers stored in the compressed vector.
This value represents the total count of decompressed integers.
Sourcepub fn get_sampling_rate(&self) -> usize
pub fn get_sampling_rate(&self) -> usize
Returns the sampling rate used by the compressed vector.
Sourcepub fn get_samples(&self) -> Vec<usize>
pub fn get_samples(&self) -> Vec<usize>
Returns the codec parameter used by the compressed vector.
Source§impl<C: Codec<LE, BufBitWriter<LE, MemWordWriterVec<u64, Vec<u64>>>, Params = ()>> IntVec<LittleEndian, BufBitWriter<LittleEndian, MemWordWriterVec<u64, Vec<u64>>>, C>
Convenience constructor for codecs with no extra runtime parameter.
impl<C: Codec<LE, BufBitWriter<LE, MemWordWriterVec<u64, Vec<u64>>>, Params = ()>> IntVec<LittleEndian, BufBitWriter<LittleEndian, MemWordWriterVec<u64, Vec<u64>>>, C>
Convenience constructor for codecs with no extra runtime parameter.
Trait Implementations§
Source§impl<E: Clone + Endianness, W: Clone + BitWrite<E>, C: Clone + Codec<E, W>> Clone for IntVec<E, W, C>
impl<E: Clone + Endianness, W: Clone + BitWrite<E>, C: Clone + Codec<E, W>> Clone for IntVec<E, W, C>
Source§impl<E: Debug + Endianness, W: Debug + BitWrite<E>, C: Debug + Codec<E, W>> Debug for IntVec<E, W, C>
impl<E: Debug + Endianness, W: Debug + BitWrite<E>, C: Debug + Codec<E, W>> Debug for IntVec<E, W, C>
Source§impl<E: Endianness, W: BitWrite<E>, C: Codec<E, W>> MemDbgImpl for IntVec<E, W, C>where
Vec<u64>: MemDbgImpl,
Vec<usize>: MemDbgImpl,
PhantomData<C>: MemDbgImpl,
usize: MemDbgImpl,
C::Params: MemDbgImpl,
PhantomData<E>: MemDbgImpl,
impl<E: Endianness, W: BitWrite<E>, C: Codec<E, W>> MemDbgImpl for IntVec<E, W, C>where
Vec<u64>: MemDbgImpl,
Vec<usize>: MemDbgImpl,
PhantomData<C>: MemDbgImpl,
usize: MemDbgImpl,
C::Params: MemDbgImpl,
PhantomData<E>: MemDbgImpl,
Auto Trait Implementations§
impl<E, W, C> Freeze for IntVec<E, W, C>
impl<E, W, C> RefUnwindSafe for IntVec<E, W, C>
impl<E, W, C> Send for IntVec<E, W, C>
impl<E, W, C> Sync for IntVec<E, W, C>
impl<E, W, C> Unpin for IntVec<E, W, C>
impl<E, W, C> UnwindSafe for IntVec<E, W, C>
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> MemDbg for Twhere
T: MemDbgImpl,
impl<T> MemDbg for Twhere
T: MemDbgImpl,
Source§fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>
fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>
Source§fn mem_dbg_on(
&self,
writer: &mut impl Write,
flags: DbgFlags,
) -> Result<(), Error>
fn mem_dbg_on( &self, writer: &mut impl Write, flags: DbgFlags, ) -> Result<(), Error>
core::fmt::Write
debug infos about the structure memory usage,
expanding all levels of nested structures.Source§fn mem_dbg_depth(
&self,
total_size: usize,
max_depth: usize,
flags: DbgFlags,
) -> Result<(), Error>
fn mem_dbg_depth( &self, total_size: usize, max_depth: usize, flags: DbgFlags, ) -> Result<(), Error>
max_depth
levels of nested structures.Source§fn mem_dbg_depth_on(
&self,
writer: &mut impl Write,
total_size: usize,
max_depth: usize,
prefix: &mut String,
field_name: Option<&str>,
is_last: bool,
flags: DbgFlags,
) -> Result<(), Error>
fn mem_dbg_depth_on( &self, writer: &mut impl Write, total_size: usize, max_depth: usize, prefix: &mut String, field_name: Option<&str>, is_last: bool, flags: DbgFlags, ) -> Result<(), Error>
core::fmt::Write
debug infos about the structure memory usage,
but expanding only up to max_depth
levels of nested structures.