pub struct CompressionConfig {
pub min_array_length: usize,
pub min_string_length: usize,
pub min_frequency_count: u32,
pub uuid_compression_potential: f32,
pub min_net_savings: usize,
pub delta_threshold: f32,
pub min_delta_potential: f32,
pub run_length_threshold: f32,
pub min_compression_potential: f32,
pub min_numeric_sequence_size: usize,
}Expand description
Configuration constants for compression algorithms
Fields§
§min_array_length: usizeMinimum array length for pattern analysis
min_string_length: usizeMinimum string length for dictionary inclusion
min_frequency_count: u32Minimum frequency for dictionary inclusion
uuid_compression_potential: f32Minimum compression potential for UUID patterns
min_net_savings: usizeMinimum net wire-byte saving required to select
CompressionStrategy::Dictionary (or the dictionary half of
CompressionStrategy::Hybrid). The net saving is computed per
candidate string as gain - cost, summed across all kept entries and
reduced by a fixed metadata envelope, using the same size accounting
the reported compressed_size uses. This makes dictionary selection a
modelled net-positive decision, not a guarantee: see the known
imprecisions below, which can make an accepted payload net-negative on
adversarial input. The wire-byte report (compressed_size and
everything derived from it) is unaffected and always measured, never
modelled (see issue #333).
For a string of length L repeated c times with per-occurrence
marker overhead m = 1 + decimal_digits(index) and per-entry
dictionary-array cost L + 3 (the string, its quotes, one
separator), an entry only pays off once c*(L-m) > L+3, i.e.
L > (c*m + 3) / (c - 1). The smallest achievable m is 2
(index 0 is one decimal digit), so for c = 2 that means
L > 7. "active" (L = 6, c = 2) fails this per-entry gate
(gain 8 < cost 9) and is pruned before min_net_savings is
consulted; a payload whose only repeated string is "active"
yields an empty dictionary and CompressionStrategy::None. Even
one kept entry rarely clears the floor alone: at c = 2 it needs
L >= 27 to reach the default min_net_savings of 10 after the
envelope.
Known imprecisions, both of which shift the modelled net toward being
optimistic (a real payload can save fewer bytes than modelled, never
more): this accounting does not model JSON string escaping inside
dictionary strings (e.g. embedded quotes or backslashes), and it does
not model the 1-byte-per-instance cost of escaping a payload string
that legitimately starts with the sentinel byte (see
substitute_dictionary_strings). Both are symmetric across ordinary
payloads and shift the byte count only slightly, but a payload
engineered to maximize sentinel-led strings can make a selected
Dictionary strategy net-negative in the real, measured report.
delta_threshold: f32Threshold score for delta compression
min_delta_potential: f32Minimum delta potential for numeric compression
run_length_threshold: f32Threshold for run-length compression
min_compression_potential: f32Minimum compression potential for pattern selection
min_numeric_sequence_size: usizeMinimum array size for numeric sequence analysis
Implementations§
Source§impl CompressionConfig
impl CompressionConfig
Sourcepub fn validate(&self) -> Result<(), ConfigError>
pub fn validate(&self) -> Result<(), ConfigError>
Validate compression configuration invariants.
§Errors
Returns ConfigError::InconsistentBounds when a potential/ratio
field (uuid_compression_potential, min_delta_potential,
min_compression_potential) is outside 0.0..=1.0, or when a
threshold field (delta_threshold, run_length_threshold) is
negative or non-finite.
§Examples
use pjson_rs::compression::CompressionConfig;
CompressionConfig::default().validate().expect("defaults are valid");Trait Implementations§
Source§impl Clone for CompressionConfig
impl Clone for CompressionConfig
Source§fn clone(&self) -> CompressionConfig
fn clone(&self) -> CompressionConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CompressionConfig
impl Debug for CompressionConfig
Auto Trait Implementations§
impl Freeze for CompressionConfig
impl RefUnwindSafe for CompressionConfig
impl Send for CompressionConfig
impl Sync for CompressionConfig
impl Unpin for CompressionConfig
impl UnsafeUnpin for CompressionConfig
impl UnwindSafe for CompressionConfig
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more