Skip to main content

RunLengthEncoding

Struct RunLengthEncoding 

Source
pub struct RunLengthEncoding { /* private fields */ }
Expand description

Run-length encoded data for u64 values.

Stores sequences of (value, count) pairs. Achieves excellent compression when data has long runs of repeated values.

Implementations§

Source§

impl RunLengthEncoding

Source

pub fn encode(values: &[u64]) -> Self

Encodes a slice of u64 values using run-length encoding.

§Example
let values = vec![1, 1, 1, 2, 2, 3];
let encoded = RunLengthEncoding::encode(&values);
// Results in 3 runs: (1, 3), (2, 2), (3, 1)
Source

pub fn from_runs(runs: Vec<Run<u64>>) -> Self

Creates a run-length encoding from pre-built runs.

Source

pub fn decode(&self) -> Vec<u64>

Decodes back to the original values.

Source

pub fn run_count(&self) -> usize

Returns the number of runs.

Source

pub fn total_count(&self) -> usize

Returns the total number of values represented.

Source

pub fn runs(&self) -> &[Run<u64>]

Returns the runs.

Source

pub fn is_empty(&self) -> bool

Returns true if there are no values.

Source

pub fn compression_ratio(&self) -> f64

Returns the compression ratio (original size / encoded size).

Values > 1.0 indicate compression, < 1.0 indicate expansion.

Source

pub fn is_beneficial(&self) -> bool

Returns true if run-length encoding is beneficial for this data.

Returns true when compression ratio > 1.0 (actual compression achieved).

Source

pub fn encoded_size(&self) -> usize

Returns the memory size in bytes of the encoded representation.

Source

pub fn to_bytes(&self) -> Vec<u8>

Serializes the run-length encoding to bytes.

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self>

Deserializes run-length encoding from bytes.

Source

pub fn get(&self, index: usize) -> Option<u64>

Gets the value at a specific index without full decompression.

Returns None if index is out of bounds.

Source

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

Returns an iterator over the decoded values.

Trait Implementations§

Source§

impl Clone for RunLengthEncoding

Source§

fn clone(&self) -> RunLengthEncoding

Returns a duplicate 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 RunLengthEncoding

Source§

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

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

impl<'a> IntoIterator for &'a RunLengthEncoding

Source§

type Item = u64

The type of the elements being iterated over.
Source§

type IntoIter = RunLengthIterator<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

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

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.