Struct sucds::int_vectors::dacs_byte::DacsByte
source · 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
impl DacsByte
sourcepub fn from_slice<T>(vals: &[T]) -> Result<Self>where
T: ToPrimitive,
pub fn from_slice<T>(vals: &[T]) -> Result<Self>where T: ToPrimitive,
sourcepub const fn iter(&self) -> Iter<'_> ⓘ
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);
sourcepub fn num_levels(&self) -> usize
pub fn num_levels(&self) -> usize
Gets the number of levels.
Trait Implementations§
source§impl Access for DacsByte
impl Access for DacsByte
source§fn access(&self, pos: usize) -> Option<usize>
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
impl Build for DacsByte
source§fn build_from_slice<T>(vals: &[T]) -> Result<Self>where
T: ToPrimitive,
Self: Sized,
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 NumVals for DacsByte
impl NumVals for DacsByte
source§fn num_vals(&self) -> usize
fn num_vals(&self) -> usize
Returns the number of integers stored (just wrapping Self::len()
).
source§impl PartialEq for DacsByte
impl PartialEq for DacsByte
source§impl Serializable for DacsByte
impl Serializable for DacsByte
source§fn serialize_into<W: Write>(&self, writer: W) -> Result<usize>
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>
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
fn size_in_bytes(&self) -> usize
Returns the number of bytes to serialize the data structure.
impl Eq for DacsByte
impl StructuralEq for DacsByte
impl StructuralPartialEq for DacsByte
Auto Trait Implementations§
impl RefUnwindSafe for DacsByte
impl Send for DacsByte
impl Sync for DacsByte
impl Unpin for DacsByte
impl UnwindSafe for DacsByte
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
Mutably borrows from an owned value. Read more