Skip to main content

LevelParameters

Struct LevelParameters 

Source
pub struct LevelParameters {
    pub window_log: u32,
    pub chain_log: u32,
    pub hash_log: u32,
    pub search_log: u32,
    pub min_match: u32,
    pub target_length: u32,
    pub strategy: Strategy,
}
Expand description

The match-finder parameters a numeric level selects for a source of a given size, the drop-in equivalent of C zstd’s ZSTD_getCParams.

The size matters: the reference’s level table has a row per source-size tier, and the tier changes the strategy as well as the table widths, so one level can run a different match-finder on a small input than on a large one. This is the selection the encoder itself makes for a frame without a dictionary; knobs set through CompressionParameters override it.

§Examples

use structured_zstd::encoding::{LevelParameters, Strategy};

// Level 11 is a lazy2 level on a large or unknown-size source...
let large = LevelParameters::for_level(11, None, 0);
assert_eq!(large.strategy, Strategy::Lazy2);

// ...and the optimal parser on one of 16 KiB or less, whose window is
// also cut down to the source.
let small = LevelParameters::for_level(11, Some(4096), 0);
assert_eq!(small.strategy, Strategy::Btopt);
assert_eq!(small.window_log, 12);

Fields§

§window_log: u32

Back-reference window, log2. C windowLog.

§chain_log: u32

Chain / binary-tree table size, log2. C chainLog.

§hash_log: u32

Hash table size, log2. C hashLog.

§search_log: u32

Search attempts per position, log2. C searchLog.

§min_match: u32

Match-finder hash width, in bytes. C minMatch.

§target_length: u32

Length that ends a search early; on a negative level, the step size minus one. C targetLength.

§strategy: Strategy

The match-finder strategy. C strategy.

Implementations§

Source§

impl LevelParameters

Source

pub fn for_level( level: i32, source_size: Option<u64>, dictionary_size: usize, ) -> Self

Parameters for level compressing a source of source_size bytes with a dictionary_size-byte dictionary (0 for none).

level is on the reference’s scale: 0 is the default level, levels above CompressionLevel::MAX_LEVEL clamp to it, and a negative level is an acceleration factor. None is a source of unknown size, which is sized as a large one; Some(0) is a source that is really empty. C ZSTD_getCParams spells unknown as 0, so a caller porting from it maps 0 to None.

Source

pub fn adjusted(self, source_size: Option<u64>, dictionary_size: usize) -> Self

These parameters fitted to a source of source_size bytes and a dictionary_size-byte dictionary, the drop-in equivalent of C zstd’s ZSTD_adjustCParams: a window wider than the data comes down to it, and the tables shrink with the window. None is a source of unknown size, which leaves the tables alone.

Every field must already lie within its CParameter::bounds.

§Examples
use structured_zstd::encoding::LevelParameters;

let level_19 = LevelParameters::for_level(19, None, 0);
let small = level_19.adjusted(Some(1000), 0);
assert_eq!(small.window_log, 10);
assert!(small.hash_log <= 11);
assert_eq!(level_19.adjusted(None, 0), level_19);

Trait Implementations§

Source§

impl Clone for LevelParameters

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for LevelParameters

Source§

impl Debug for LevelParameters

Source§

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

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

impl Eq for LevelParameters

Source§

impl PartialEq for LevelParameters

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LevelParameters

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> 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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.