Struct IntVec

Source
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 or LE).
  • W: A bit writer implementing BitWrite<E>.
  • C: A codec implementing Codec<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>

Source

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());
Source

pub fn from(input: &[u64], k: usize) -> Result<Self, Box<dyn Error>>
where C::Params: Default,

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());
Source

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);
Source

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);
Source

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());
Source

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());
Source

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);
Source

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());
Source

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());
Source

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>
where C::Params: Clone,

Source§

fn clone(&self) -> IntVec<E, W, C>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<E: Endianness, W: BitWrite<E>, C: Codec<E, W>> CopyType 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>
where C::Params: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<E: Endianness, W: BitWrite<E>, C: Codec<E, W>> MemDbgImpl for IntVec<E, W, C>

Source§

fn _mem_dbg_rec_on( &self, _memdbg_writer: &mut impl Write, _memdbg_total_size: usize, _memdbg_max_depth: usize, _memdbg_prefix: &mut String, _memdbg_is_last: bool, _memdbg_flags: DbgFlags, ) -> Result

Source§

impl<E: Endianness, W: BitWrite<E>, C: Codec<E, W>> MemSize for IntVec<E, W, C>

Source§

fn mem_size(&self, _memsize_flags: SizeFlags) -> usize

Return the (recursively computed) overall memory size of the structure in bytes.

Auto Trait Implementations§

§

impl<E, W, C> Freeze for IntVec<E, W, C>
where <C as Codec<E, W>>::Params: Freeze,

§

impl<E, W, C> RefUnwindSafe for IntVec<E, W, C>
where <C as Codec<E, W>>::Params: RefUnwindSafe, C: RefUnwindSafe, E: RefUnwindSafe,

§

impl<E, W, C> Send for IntVec<E, W, C>
where <C as Codec<E, W>>::Params: Send, C: Send, E: Send,

§

impl<E, W, C> Sync for IntVec<E, W, C>
where <C as Codec<E, W>>::Params: Sync, C: Sync, E: Sync,

§

impl<E, W, C> Unpin for IntVec<E, W, C>
where <C as Codec<E, W>>::Params: Unpin, C: Unpin, E: Unpin,

§

impl<E, W, C> UnwindSafe for IntVec<E, W, C>
where <C as Codec<E, W>>::Params: UnwindSafe, C: UnwindSafe, E: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CastableFrom<T> for T

Source§

fn cast_from(value: T) -> T

Call Self as W
Source§

impl<T, U> CastableInto<U> for T
where U: CastableFrom<T>,

Source§

fn cast(self) -> U

Call W::cast_from(self)
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> DowncastableFrom<T> for T

Source§

fn downcast_from(value: T) -> T

Truncate the current UnsignedInt to a possibly smaller size
Source§

impl<T, U> DowncastableInto<U> for T
where U: DowncastableFrom<T>,

Source§

fn downcast(self) -> U

Call W::downcast_from(self)
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> MemDbg for T
where T: MemDbgImpl,

Source§

fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>

Write to stdout debug infos about the structure memory usage, expanding all levels of nested structures.
Source§

fn mem_dbg_on( &self, writer: &mut impl Write, flags: DbgFlags, ) -> Result<(), Error>

Write to a 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>

Write to stdout debug infos about the structure memory usage, but expanding only up to 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>

Write to a core::fmt::Write debug infos about the structure memory usage, but expanding only up to max_depth levels of nested structures.
Source§

impl<T> Splat<T> for T

Source§

fn splat(value: T) -> T

Source§

impl<T> To<T> for T

Source§

fn to(self) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UpcastableFrom<T> for T

Source§

fn upcast_from(value: T) -> T

Extend the current UnsignedInt to a possibly bigger size.
Source§

impl<T, U> UpcastableInto<U> for T
where U: UpcastableFrom<T>,

Source§

fn upcast(self) -> U

Call W::upcast_from(self)
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V