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
impl PrefixSummedEliasFano
sourcepub fn from_slice<T>(vals: &[T]) -> Result<Self>where
T: ToPrimitive,
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 tousize
, orvals
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);
sourcepub const fn iter(&self) -> Iter<'_> ⓘ
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);
Trait Implementations§
source§impl Access for PrefixSummedEliasFano
impl Access for PrefixSummedEliasFano
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
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
impl Build for PrefixSummedEliasFano
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 Clone for PrefixSummedEliasFano
impl Clone for PrefixSummedEliasFano
source§fn clone(&self) -> PrefixSummedEliasFano
fn clone(&self) -> PrefixSummedEliasFano
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for PrefixSummedEliasFano
impl Debug for PrefixSummedEliasFano
source§impl Default for PrefixSummedEliasFano
impl Default for PrefixSummedEliasFano
source§fn default() -> PrefixSummedEliasFano
fn default() -> PrefixSummedEliasFano
Returns the “default value” for a type. Read more
source§impl NumVals for PrefixSummedEliasFano
impl NumVals for PrefixSummedEliasFano
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 PrefixSummedEliasFano
impl PartialEq for PrefixSummedEliasFano
source§fn eq(&self, other: &PrefixSummedEliasFano) -> bool
fn eq(&self, other: &PrefixSummedEliasFano) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl Serializable for PrefixSummedEliasFano
impl Serializable for PrefixSummedEliasFano
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 PrefixSummedEliasFano
impl StructuralEq for PrefixSummedEliasFano
impl StructuralPartialEq for PrefixSummedEliasFano
Auto Trait Implementations§
impl RefUnwindSafe for PrefixSummedEliasFano
impl Send for PrefixSummedEliasFano
impl Sync for PrefixSummedEliasFano
impl Unpin for PrefixSummedEliasFano
impl UnwindSafe for PrefixSummedEliasFano
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