pub struct DacsByte { /* private fields */ }
Expand description

Compressed integer sequence using Directly Addressable Codes (DACs) in a simple bytewise scheme.

DACs are a compact representation of an integer sequence consisting of many small values. DacsByte is a simple variant and uses Vec<u8> for each level to obtain faster operations than DacsOpt.

Memory complexity

$\textrm{DAC}(A) + o(\textrm{DAC}(A)/b) + O(\lg u)$ bits where

  • $u$ is the maximum value plus 1,
  • $b$ is the length in bits assigned for each level with DACs (here $b = 8$), and
  • $\textrm{DAC}(A)$ is the length in bits of the encoded sequence from an original sequence $A$ with DACs.

Examples

use sucds::int_vectors::{DacsByte, Access};

let seq = DacsByte::from_slice(&[5, 0, 100000, 334])?;

assert_eq!(seq.access(0), Some(5));
assert_eq!(seq.access(1), Some(0));
assert_eq!(seq.access(2), Some(100000));
assert_eq!(seq.access(3), Some(334));

assert_eq!(seq.len(), 4);
assert_eq!(seq.num_levels(), 3);

References

  • N. R. Brisaboa, S. Ladra, and G. Navarro, “DACs: Bringing direct access to variable-length codes.” Information Processing & Management, 49(1), 392-404, 2013.

Implementations§

source§

impl DacsByte

source

pub fn from_slice<T>(vals: &[T]) -> Result<Self>where T: ToPrimitive,

Builds DACs by assigning 8 bits to represent each level.

Arguments
  • vals: Slice of integers to be stored.
Errors

An error is returned if vals contains an integer that cannot be cast to usize.

source

pub const fn iter(&self) -> Iter<'_>

Creates an iterator for enumerating integers.

Examples
use sucds::int_vectors::DacsByte;

let seq = DacsByte::from_slice(&[5, 0, 100000, 334])?;
let mut it = seq.iter();

assert_eq!(it.next(), Some(5));
assert_eq!(it.next(), Some(0));
assert_eq!(it.next(), Some(100000));
assert_eq!(it.next(), Some(334));
assert_eq!(it.next(), None);
source

pub fn len(&self) -> usize

Gets the number of integers.

source

pub fn is_empty(&self) -> bool

Checks if the vector is empty.

source

pub fn num_levels(&self) -> usize

Gets the number of levels.

source

pub fn widths(&self) -> Vec<usize>

Gets the number of bits for each level.

Trait Implementations§

source§

impl Access for DacsByte

source§

fn access(&self, pos: usize) -> Option<usize>

Returns the pos-th integer, or None if out of bounds.

Complexity

$O( \ell_{pos} )$ where $\ell_{pos}$ is the number of levels corresponding to the pos-th integer.

Examples
use sucds::int_vectors::{DacsByte, Access};

let seq = DacsByte::from_slice(&[5, 999, 334])?;

assert_eq!(seq.access(0), Some(5));
assert_eq!(seq.access(1), Some(999));
assert_eq!(seq.access(2), Some(334));
assert_eq!(seq.access(3), None);
source§

impl Build for DacsByte

source§

fn build_from_slice<T>(vals: &[T]) -> Result<Self>where T: ToPrimitive, Self: Sized,

Creates a new vector from a slice of integers vals.

This just calls Self::from_slice(). See the documentation.

source§

impl Clone for DacsByte

source§

fn clone(&self) -> DacsByte

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 Debug for DacsByte

source§

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

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

impl Default for DacsByte

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl NumVals for DacsByte

source§

fn num_vals(&self) -> usize

Returns the number of integers stored (just wrapping Self::len()).

source§

impl PartialEq for DacsByte

source§

fn eq(&self, other: &DacsByte) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serializable for DacsByte

source§

fn serialize_into<W: Write>(&self, writer: W) -> Result<usize>

Serializes the data structure into the writer, returning the number of serialized bytes. Read more
source§

fn deserialize_from<R: Read>(reader: R) -> Result<Self>

Deserializes the data structure from the reader. Read more
source§

fn size_in_bytes(&self) -> usize

Returns the number of bytes to serialize the data structure.
source§

fn size_of() -> Option<usize>

Returns the size of a primitive type in bytes (if the type is so).
source§

impl Eq for DacsByte

source§

impl StructuralEq for DacsByte

source§

impl StructuralPartialEq for DacsByte

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.