Skip to main content

FractalCompressor

Struct FractalCompressor 

Source
pub struct FractalCompressor;
Expand description

Fractal compression engine.

Implementations§

Source§

impl FractalCompressor

Source

pub fn new() -> Self

Source

pub fn compress( &self, coord: &FiveDimCoord, chaos_seed: &[u8; 32], target_dims: usize, ) -> Result<IfsCodebook, PrivacyError>

Compress a 5D manifold vertex using IFS.

Identifies self-similar patterns via barnsley-style collage theorem. Chaos perturbation modulates transformation coefficients.

Source

pub fn compress_bytes( &self, data: &[u8], ) -> Result<CompressedBlob, PrivacyError>

Losslessly compress byte data with DEFLATE (RFC 1951), falling back to storing it verbatim when that does not make it smaller.

This is not fractal compression and does not use the IFS machinery above — see the module doc comment for why. The round-trip through decompress_bytes is exact.

The fallback is what keeps the output from growing: no algorithm compresses every input, so incompressible data (already-compressed bytes, ciphertext, high-entropy keys — much of what this crate handles) is stored as-is and flagged in CompressedBlob::stored.

Source

pub fn decompress( &self, codebook: &IfsCodebook, ) -> Result<FiveDimCoord, PrivacyError>

Decompress an IFS codebook back to a 5D coordinate.

Iterates the IFS attractor for 100 steps.

Source

pub fn decompress_bytes(blob: &CompressedBlob) -> Result<Vec<u8>, PrivacyError>

Recover the exact bytes a CompressedBlob was built from.

Inflates the DEFLATE stream, or returns the stored bytes when CompressedBlob::stored is set, then checks both the recovered length and its SHA-256 against what the blob recorded. A mismatch is reported as an error rather than returned to the caller.

Source

pub fn compress_and_verify( &self, data: &[u8], ) -> Result<(CompressedBlob, Vec<u8>), PrivacyError>

Compress data and immediately prove the round-trip recovers it exactly.

Unlike the earlier version of this method, this can genuinely fail: the compression path is real, so a defect in it surfaces here rather than being masked by the input having been stored verbatim.

Returns (blob, decompressed), where decompressed == data.

Source

pub fn compression_ratio(original_dims: usize, codebook: &IfsCodebook) -> f64

Storage ratio for the IFS path: original coordinate size over the size of the transforms that replace it.

This describes dimension reduction on a FiveDimCoord, not byte compression. For that, use CompressedBlob::ratio.

Trait Implementations§

Source§

impl Default for FractalCompressor

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.