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: u64The total number of elements observed.
unary: u64The total space used to store the elements if they were stored using the unary code.
gamma: u64The total space used to store the elements if they were stored using the gamma code.
delta: u64The total space used to store the elements if they were stored using the delta code.
omega: u64The total space used to store the elements if they were stored using the omega code.
vbyte: u64The 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>
impl<const ZETA: usize, const GOLOMB: usize, const EXP_GOLOMB: usize, const RICE: usize, const PI: usize> CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>
Sourcepub fn update(&mut self, n: u64) -> u64
pub fn update(&mut self, n: u64) -> u64
Update the stats with the lengths of the codes for n and return
n for convenience.
Sourcepub fn update_many(&mut self, n: u64, count: u64) -> u64
pub fn update_many(&mut self, n: u64, count: u64) -> u64
Update the stats with count occurrences of n and return n for convenience.
Sourcepub fn best_code(&self) -> (Codes, u64)
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).
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>
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§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>
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)
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>
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>
fn clone(&self) -> CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§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>
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§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>
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§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.
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>
serde only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
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>
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>where
u64: MemDbgImpl + FlatType,
[u64; ZETA]: MemDbgImpl + FlatType,
[u64; GOLOMB]: MemDbgImpl + FlatType,
[u64; EXP_GOLOMB]: MemDbgImpl + FlatType,
[u64; RICE]: MemDbgImpl + FlatType,
[u64; PI]: MemDbgImpl + FlatType,
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>where
u64: MemDbgImpl + FlatType,
[u64; ZETA]: MemDbgImpl + FlatType,
[u64; GOLOMB]: MemDbgImpl + FlatType,
[u64; EXP_GOLOMB]: MemDbgImpl + FlatType,
[u64; RICE]: MemDbgImpl + FlatType,
[u64; PI]: MemDbgImpl + FlatType,
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
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>
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>
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>
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§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>
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
fn eq(&self, other: &CodesStats<ZETA, GOLOMB, EXP_GOLOMB, RICE, PI>) -> bool
self and other values to be equal, and is used by ==.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.
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>
serde only.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.
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.
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>
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>
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> 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> MemDbg for Twhere
T: MemDbgImpl,
impl<T> MemDbg for Twhere
T: MemDbgImpl,
Source§fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>
fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>
Source§fn mem_dbg_on(
&self,
writer: &mut impl Write,
flags: DbgFlags,
) -> Result<(), Error>
fn mem_dbg_on( &self, writer: &mut impl Write, flags: DbgFlags, ) -> Result<(), Error>
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>
fn mem_dbg_depth(&self, max_depth: usize, flags: DbgFlags) -> Result<(), Error>
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>
fn mem_dbg_depth_on( &self, writer: &mut impl Write, max_depth: usize, flags: DbgFlags, ) -> Result<(), Error>
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.