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

Compressed integer sequence with prefix-summed Elias-Fano encoding.

This stores a sequence of integers by converting it into an increasing sequence in a prefix-summing manner and representing it through the Elias-Fano encoding.

Memory complexity

$n \lceil \lg \frac{N}{n} \rceil + 2n + o(n)$ bits where

  • $n$ is the number of stored integers, and
  • $N$ is the sum of integers plus 1.

Examples

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

let seq = PrefixSummedEliasFano::from_slice(&[5, 14, 334, 10])?;

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

assert_eq!(seq.len(), 4);
assert_eq!(seq.sum(), 363);

Credits

This is a yet another Rust port of succinct::elias_fano_list.

References

  • P. Elias, “Efficient storage and retrieval by content and address of static files,” Journal of the ACM, 1974.
  • R. Fano, “On the number of bits required to implement an associative memory,” Memorandum 61. Computer Structures Group, Project MAC, MIT, 1971.
  • D. Okanohara, and K. Sadakane, “Practical Entropy-Compressed Rank/Select Dictionary,” In ALENEX, 2007.

Implementations§

source§

impl PrefixSummedEliasFano

source

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

Creates a new sequence from a slice of integers.

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

An error is returned if

  • vals contains an integer that cannot be cast to usize, or
  • vals is empty.
Examples
use sucds::int_vectors::PrefixSummedEliasFano;

let seq = PrefixSummedEliasFano::from_slice(&[5, 14, 334, 10])?;

assert_eq!(seq.len(), 4);
assert_eq!(seq.sum(), 363);
source

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

Creates an iterator for enumerating integers.

Examples
use sucds::int_vectors::PrefixSummedEliasFano;

let seq = PrefixSummedEliasFano::from_slice(&[5, 14, 334, 10])?;
let mut it = seq.iter();

assert_eq!(it.next(), Some(5));
assert_eq!(it.next(), Some(14));
assert_eq!(it.next(), Some(334));
assert_eq!(it.next(), Some(10));
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 sequence is empty.

source

pub const fn sum(&self) -> usize

Gets the sum of integers.

Trait Implementations§

source§

impl Access for PrefixSummedEliasFano

source§

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

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

Complexity

Constant

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

let seq = PrefixSummedEliasFano::from_slice(&[5, 14, 334])?;
assert_eq!(seq.access(0), Some(5));
assert_eq!(seq.access(1), Some(14));
assert_eq!(seq.access(2), Some(334));
assert_eq!(seq.access(3), None);
source§

impl Build for PrefixSummedEliasFano

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 PrefixSummedEliasFano

source§

fn clone(&self) -> PrefixSummedEliasFano

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 PrefixSummedEliasFano

source§

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

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

impl Default for PrefixSummedEliasFano

source§

fn default() -> PrefixSummedEliasFano

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

impl NumVals for PrefixSummedEliasFano

source§

fn num_vals(&self) -> usize

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

source§

impl PartialEq for PrefixSummedEliasFano

source§

fn eq(&self, other: &PrefixSummedEliasFano) -> 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 PrefixSummedEliasFano

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 PrefixSummedEliasFano

source§

impl StructuralEq for PrefixSummedEliasFano

source§

impl StructuralPartialEq for PrefixSummedEliasFano

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.