Skip to main content

Adaptive

Struct Adaptive 

Source
pub struct Adaptive { /* private fields */ }
Available on crate feature adaptive only.
Expand description

Network-aware level chooser that learns from previous calls.

Each call that keeps a compressed frame records the compression speed and wire ratio of the level it chose. choice minimizes the normalized transfer cost net_speed / speed + ratio against 1 / 1.05 and picks the fastest option.

Implementations§

Source§

impl Adaptive

Source

pub const fn new() -> Self

Creates an instance with built-in priors; observations replace them.

Source

pub fn choice(&self, net_speed: u64) -> Choice

Returns the mode for a network speed in bytes per second.

0 means the network speed is unknown and selects Level::Balanced.

Source

pub fn encode(&mut self, data: &[u8], net_speed: u64) -> Vec<u8> ⓘ

Compresses with the level chosen for net_speed and records the result.

net_speed is in bytes per second; 0 selects Level::Balanced and still records measurements, which is useful for training the model. Raw fallbacks and inputs below 8 KiB are not recorded.

Source

pub fn encode_owned(&mut self, data: Vec<u8>, net_speed: u64) -> Encoded

Encodes an owned buffer and records the result like Self::encode.

Raw decisions return the input allocation unchanged, so no payload bytes are copied. Use Encoded::into_parts to write the tag and payload as two owned buffers.

Source

pub fn encode_into( &mut self, data: &[u8], net_speed: u64, out: &mut Vec<u8>, ) -> Type

Encodes into out and records the result like Self::encode.

The buffer is reused across calls; out holds a complete envelope on return.

Source

pub fn observe(&mut self, level: Level, speed: f64, ratio: f64)

Records a compression measurement for level and updates estimates.

Non-finite or non-positive speeds and non-finite ratios are ignored. Unmeasured neighbor levels scale proportionally to keep relative priors calibrated while maintaining monotonic ordering across all presets.

Source

pub fn stats(&self) -> [Stat; 5]

Current estimates, ordered as Level::ALL.

Faster levels are never slower and never compress better.

Trait Implementations§

Source§

impl Clone for Adaptive

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 Debug for Adaptive

Source§

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

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

impl Default for Adaptive

Source§

fn default() -> Self

Returns the “default value” for a type. 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, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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.