pub struct Adaptive { /* private fields */ }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
impl Adaptive
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates an instance with built-in priors; observations replace them.
Sourcepub fn choice(&self, net_speed: u64) -> Choice
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.
Sourcepub fn encode(&mut self, data: &[u8], net_speed: u64) -> Vec<u8> ⓘ
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.
Sourcepub fn encode_owned(&mut self, data: Vec<u8>, net_speed: u64) -> Encoded
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.
Sourcepub fn encode_into(
&mut self,
data: &[u8],
net_speed: u64,
out: &mut Vec<u8>,
) -> Type
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.
Sourcepub fn observe(&mut self, level: Level, speed: f64, ratio: f64)
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.
Sourcepub fn stats(&self) -> [Stat; 5]
pub fn stats(&self) -> [Stat; 5]
Current estimates, ordered as Level::ALL.
Faster levels are never slower and never compress better.