pub struct IntVec<E: Endianness, W: BitWrite<E>, C: Codec<E, W>> { /* private fields */ }
Expand description
A compressed vector of unsigned 64-bit integers using a specified codec.
The IntVec
structure compresses a sequence of u64
values by encoding them using a
provided codec. It supports random access via sampling and iteration over the decompressed
values.
The type parameters are:
E
: Endianness to use (BE
orLE
).W
: A bit writer implementingBitWrite<E>
.C
: A codec implementingCodec<E, W>
.
§Examples
use compressed_intvec::intvec::IntVec;
use compressed_intvec::codecs::GammaCodec;
use dsi_bitstream::traits::BE;
let input = vec![1, 2, 3, 4, 5];
let k = 2;
let intvec = IntVec::<BE, _, GammaCodec>::from(&input, k).unwrap();
assert_eq!(intvec.len(), input.len());
Implementations§
Source§impl<E, C> IntVec<E, BufBitWriter<E, MemWordWriterVec<u64, Vec<u64>>>, C>where
E: Endianness,
C: Codec<E, BufBitWriter<E, MemWordWriterVec<u64, Vec<u64>>>>,
C::Params: Copy,
BufBitWriter<E, MemWordWriterVec<u64, Vec<u64>>>: BitWrite<E>,
for<'a> BufBitReader<E, MemWordReader<u64, &'a Vec<u64>>>: GammaRead<E> + DeltaRead<E> + ZetaRead<E> + ZetaReadParam<E> + DeltaReadParam<E>,
impl<E, C> IntVec<E, BufBitWriter<E, MemWordWriterVec<u64, Vec<u64>>>, C>where
E: Endianness,
C: Codec<E, BufBitWriter<E, MemWordWriterVec<u64, Vec<u64>>>>,
C::Params: Copy,
BufBitWriter<E, MemWordWriterVec<u64, Vec<u64>>>: BitWrite<E>,
for<'a> BufBitReader<E, MemWordReader<u64, &'a Vec<u64>>>: GammaRead<E> + DeltaRead<E> + ZetaRead<E> + ZetaReadParam<E> + DeltaReadParam<E>,
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>>
Constructs an IntVec
from a slice of u64
values using the provided codec parameters.
This method encodes the input values using the specified codec. It also builds sampling
information for efficient random access. The parameter k
determines the sampling rate,
i.e. every kth element’s bit position is recorded as a sample.
§Parameters
input
: A slice of unsigned 64-bit integers to compress.k
: The sampling rate; every kth element will have its bit offset stored.codec_param
: The parameters for the codec used for encoding.
§Returns
Returns Ok(IntVec)
on success or an error if encoding fails.
§Examples
use compressed_intvec::intvec::IntVec;
use compressed_intvec::codecs::GammaCodec;
use dsi_bitstream::traits::BE;
let input = vec![10, 20, 30, 40];
let k = 2;
let intvec = IntVec::<BE, _, GammaCodec>::from(&input, k).unwrap();
assert_eq!(intvec.len(), input.len());
Sourcepub fn from(input: &[u64], k: usize) -> Result<Self, Box<dyn Error>>
pub fn from(input: &[u64], k: usize) -> Result<Self, Box<dyn Error>>
Constructs an IntVec
from a slice of u64
values using the default codec parameters.
This is a convenience method that calls from_with_param
with C::Params::default()
.
§Parameters
input
: A slice of unsigned 64-bit integers to compress.k
: The sampling rate; every kth element will have its bit offset stored.
§Returns
Returns Ok(IntVec)
on success or an error if encoding fails.
§Examples
use compressed_intvec::intvec::IntVec;
use compressed_intvec::codecs::GammaCodec;
use dsi_bitstream::traits::BE;
let input = vec![5, 10, 15, 20];
let k = 2;
let intvec = IntVec::<BE, _, GammaCodec>::from(&input, k).unwrap();
assert_eq!(intvec.len(), input.len());
Sourcepub fn get(&self, index: usize) -> u64
pub fn get(&self, index: usize) -> u64
Retrieves the element at the specified index after decompressing the value.
This method uses the sampling information to quickly locate the encoded bit-stream position and decodes the required value.
§Panics
Panics if the index is out of bounds.
§Parameters
index
: The index of the desired element.
§Returns
Returns the u64
value at the given index.
§Examples
use compressed_intvec::intvec::IntVec;
use compressed_intvec::codecs::GammaCodec;
use dsi_bitstream::traits::BE;
let input = vec![3, 6, 9];
let k = 1;
let intvec = IntVec::<BE, _, GammaCodec>::from(&input, k).unwrap();
assert_eq!(intvec.get(1), 6);
Sourcepub fn into_vec(self) -> Vec<u64>
pub fn into_vec(self) -> Vec<u64>
Consumes the IntVec
and returns a vector containing all decompressed u64
values.
This method sequentially decodes all the values from the compressed representation
into a standard Vec<u64>
.
§Returns
A vector of decompressed values.
§Examples
use compressed_intvec::intvec::IntVec;
use compressed_intvec::codecs::GammaCodec;
use dsi_bitstream::traits::LE;
let input = vec![7, 14, 21];
let k = 2;
let intvec = IntVec::<LE, _, GammaCodec>::from(&input, k).unwrap();
let output = intvec.into_vec();
assert_eq!(output, input);
Sourcepub fn limbs(&self) -> Vec<u64>
pub fn limbs(&self) -> Vec<u64>
Returns the underlying storage (limbs) of the compressed bitstream.
The limbs are stored as a vector of u64
, which represents the raw compressed data.
§Returns
A clone of the internal vector of limbs.
§Examples
use compressed_intvec::intvec::IntVec;
use compressed_intvec::codecs::GammaCodec;
use dsi_bitstream::traits::BE;
let input = vec![2, 4, 6, 8];
let k = 2;
let intvec = IntVec::<BE, _, GammaCodec>::from(&input, k).unwrap();
let limbs = intvec.limbs();
assert!(!limbs.is_empty());
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements encoded in the IntVec
.
§Returns
The length (number of original elements) as a usize.
§Examples
use compressed_intvec::intvec::IntVec;
use compressed_intvec::codecs::GammaCodec;
use dsi_bitstream::traits::BE;
let input = vec![1, 2, 3];
let k = 2;
let intvec = IntVec::<BE, _, GammaCodec>::from(&input, k).unwrap();
assert_eq!(intvec.len(), input.len());
Sourcepub fn get_sampling_rate(&self) -> usize
pub fn get_sampling_rate(&self) -> usize
Returns the sampling rate k
used during encoding.
This value indicates that every kth element’s bit offset was stored for efficient access.
§Returns
The sampling rate as usize.
§Examples
use compressed_intvec::intvec::IntVec;
use compressed_intvec::codecs::GammaCodec;
use dsi_bitstream::traits::BE;
let input = vec![5, 10, 15, 20];
let k = 2;
let intvec = IntVec::<BE, _, GammaCodec>::from(&input, k).unwrap();
assert_eq!(intvec.get_sampling_rate(), k);
Sourcepub fn get_samples(&self) -> Vec<usize>
pub fn get_samples(&self) -> Vec<usize>
Returns the recorded sample bit positions used for random access.
The returned vector contains the bit-offset positions for every kth element in the original data.
§Returns
A vector of sample positions.
§Examples
use compressed_intvec::intvec::IntVec;
use compressed_intvec::codecs::GammaCodec;
use dsi_bitstream::traits::BE;
let input = vec![10, 20, 30, 40, 50];
let k = 2;
let intvec = IntVec::<BE, _, GammaCodec>::from(&input, k).unwrap();
let samples = intvec.get_samples();
assert!(!samples.is_empty());
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if the IntVec
contains no encoded elements.
§Returns
true
if there are no elements, false
otherwise.
§Examples
use compressed_intvec::intvec::IntVec;
use compressed_intvec::codecs::GammaCodec;
use dsi_bitstream::traits::BE;
let empty_intvec: IntVec<BE, _, GammaCodec> = IntVec::from(&[], 2).unwrap();
assert!(empty_intvec.is_empty());
Sourcepub fn iter(&self) -> IntVecIter<'_, E, C> ⓘ
pub fn iter(&self) -> IntVecIter<'_, E, C> ⓘ
Returns an iterator over the decompressed values contained in the IntVec
.
The iterator decodes each value in sequence and yields it.
§Returns
An IntVecIter
instance that implements Iterator<Item = u64>
.
§Examples
use compressed_intvec::intvec::IntVec;
use compressed_intvec::codecs::GammaCodec;
use dsi_bitstream::traits::BE;
let input = vec![1, 3, 5, 7];
let k = 1;
let intvec = IntVec::<BE, _, GammaCodec>::from(&input, k).unwrap();
let mut iter = intvec.iter();
for value in input {
assert_eq!(iter.next(), Some(value));
}
assert_eq!(iter.next(), None);
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,
usize: MemDbgImpl,
C::Params: MemDbgImpl,
PhantomData<C>: 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,
usize: MemDbgImpl,
C::Params: MemDbgImpl,
PhantomData<C>: 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.