Skip to main content

CodesStats

Struct CodesStats 

Source
pub struct CodesStats<const ZETA: usize = 10, const GOLOMB: usize = 10, const EXP_GOLOMB: usize = 10, const RICE: usize = 10, const PI: usize = 10> {
    pub total: u64,
    pub unary: u64,
    pub gamma: u64,
    pub delta: u64,
    pub omega: u64,
    pub vbyte: u64,
    pub zeta: [u64; ZETA],
    pub golomb: [u64; GOLOMB],
    pub exp_golomb: [u64; EXP_GOLOMB],
    pub rice: [u64; RICE],
    pub pi: [u64; PI],
}
Expand description

Keeps track of the space needed to store a stream of integers using different codes.

This structure can be used to determine empirically which code provides the best compression for a given stream. You have to update the structure with the integers in the stream; at any time, you can examine the statistics or call best_code to get the best code.

The structure keeps tracks of the codes for which the module code_consts provide constants.

Fields§

§total: u64

The total number of elements observed.

§unary: u64

The total space used to store the elements if they were stored using the unary code.

§gamma: u64

The total space used to store the elements if they were stored using the gamma code.

§delta: u64

The total space used to store the elements if they were stored using the delta code.

§omega: u64

The total space used to store the elements if they were stored using the omega code.

§vbyte: u64

The total space used to store the elements if they were stored using the variable byte code.

§zeta: [u64; ZETA]

The total space used to store the elements if they were stored using a zeta code. zeta[0] represents ζ₁, zeta[1] represents ζ₂, and so on.

§golomb: [u64; GOLOMB]

The total space used to store the elements if they were stored using a Golomb code. golomb[0] represents the Golomb code with modulus 1, golomb[1] represents the Golomb code with modulus 2, and so on.

§exp_golomb: [u64; EXP_GOLOMB]

The total space used to store the elements if they were stored using an exponential Golomb code. exp_golomb[0] represents the exponential Golomb code with parameter 0, exp_golomb[1] with parameter 1, and so on.

§rice: [u64; RICE]

The total space used to store the elements if they were stored using a Rice code. rice[0] represents the Rice code with log₂(b) = 0, rice[1] with log₂(b) = 1, and so on.

§pi: [u64; PI]

The total space used to store the elements if they were stored using a pi code. pi[0] represents π₂, pi[1] represents π₃, and so on.

Implementations§

Source§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Source

pub fn update(&mut self, n: u64) -> u64

Update the stats with the lengths of the codes for n and return n for convenience.

Source

pub fn update_many(&mut self, n: u64, count: u64) -> u64

Update the stats with count occurrences of n and return n for convenience.

Source

pub fn add(&mut self, rhs: &Self)

Combines additively this stats with another one.

Source

pub fn best_code(&self) -> (Codes, u64)

Returns the best code for the stream and its space usage.

When VByte is the best code, Codes::VByteBe is returned as the canonical representative (both variants have the same bit length).

Source

pub fn get_codes(&self) -> Vec<(Codes, u64)>

Returns a vector of all codes and their space usage, in ascending order by space usage.

Source

pub fn bits_for(&self, code: Codes) -> Option<u64>

Returns the number of bits used by the given code.

Trait Implementations§

Source§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> Add for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Source§

fn add(self, rhs: Self) -> Self

Combines additively this stats with another one, creating a new one.

Source§

type Output = CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

The resulting type after applying the + operator.
Source§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> AddAssign for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Source§

fn add_assign(&mut self, rhs: Self)

Combines additively this stats with another one.

Source§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> Clone for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Source§

fn clone(&self) -> CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

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<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> Debug for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Source§

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

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

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> Default for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Source§

fn default() -> Self

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

impl<'de, const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> Deserialize<'de> for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> FlatType for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Source§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> MemDbgImpl for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Source§

fn _mem_dbg_rec_on( &self, _memdbg_writer: &mut impl Write, _memdbg_total_size: usize, _memdbg_max_depth: usize, _memdbg_prefix: &mut String, _memdbg_is_last: bool, _memdbg_flags: DbgFlags, _memdbg_refs: &mut HashSet<usize>, ) -> Result

Source§

fn _mem_dbg_depth_on( &self, writer: &mut impl Write, total_size: usize, max_depth: usize, prefix: &mut String, field_name: Option<&str>, is_last: bool, padded_size: usize, flags: DbgFlags, dbg_refs: &mut HashSet<usize>, ) -> Result<(), Error>

Source§

fn _mem_dbg_depth_on_impl( &self, writer: &mut impl Write, total_size: usize, max_depth: usize, prefix: &mut String, field_name: Option<&str>, is_last: bool, padded_size: usize, flags: DbgFlags, dbg_refs: &mut HashSet<usize>, ref_display: RefDisplay, ) -> Result<(), Error>

Internal implementation for depth display. Read more
Source§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> MemSize for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Source§

fn mem_size_rec( &self, _memsize_flags: SizeFlags, _memsize_refs: &mut HashMap<usize, usize>, ) -> usize

Recursive implementation that tracks visited references for deduplication. Read more
Source§

fn mem_size(&self, flags: SizeFlags) -> usize

Returns the (recursively computed) overall memory size of the structure in bytes.
Source§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> PartialEq for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Source§

fn eq(&self, other: &CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> Serialize for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Available on crate feature serde only.
Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> Sum for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Allows calling .sum() on an iterator of CodesStats.

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> Copy for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Source§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> Eq for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Source§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> StructuralPartialEq for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

Auto Trait Implementations§

§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> Freeze for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> RefUnwindSafe for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> Send for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> Sync for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> Unpin for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> UnsafeUnpin for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

§

impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> UnwindSafe for CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> MemDbg for T
where T: MemDbgImpl,

Source§

fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>

Writes to stderr debug info about the structure memory usage, expanding all levels of nested structures.
Source§

fn mem_dbg_on( &self, writer: &mut impl Write, flags: DbgFlags, ) -> Result<(), Error>

Writes to a core::fmt::Write debug info about the structure memory usage, expanding all levels of nested structures.
Source§

fn mem_dbg_depth(&self, max_depth: usize, flags: DbgFlags) -> Result<(), Error>

Writes to stderr debug info about the structure memory usage as mem_dbg, but expanding only up to max_depth levels of nested structures.
Source§

fn mem_dbg_depth_on( &self, writer: &mut impl Write, max_depth: usize, flags: DbgFlags, ) -> Result<(), Error>

Writes to a core::fmt::Write debug info about the structure memory usage as mem_dbg_on, but expanding only up to max_depth levels of nested structures.
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,