Struct LzssEncoder

Source
pub struct LzssEncoder<F>
where F: Fn(LzssCode, LzssCode) -> Ordering + Copy,
{ /* private fields */ }
Expand description

§Examples

use compression::prelude::*;
use std::cmp::Ordering;

fn main() {
    pub fn comparison(lhs: LzssCode, rhs: LzssCode) -> Ordering {
        match (lhs, rhs) {
            (
                LzssCode::Reference {
                    len: llen,
                    pos: lpos,
                },
                LzssCode::Reference {
                    len: rlen,
                    pos: rpos,
                },
            ) => ((llen << 3) + rpos).cmp(&((rlen << 3) + lpos)).reverse(),
            (LzssCode::Symbol(_), LzssCode::Symbol(_)) => Ordering::Equal,
            (_, LzssCode::Symbol(_)) => Ordering::Greater,
            (LzssCode::Symbol(_), _) => Ordering::Less,
        }
    }
    let compressed = b"aabbaabbaabbaabb\n"
        .into_iter()
        .cloned()
        .encode(&mut LzssEncoder::new(comparison, 0x1_0000, 256, 3, 3), Action::Finish)
        .collect::<Result<Vec<_>, _>>()
        .unwrap();

    let decompressed = compressed
        .iter()
        .cloned()
        .decode(&mut LzssDecoder::new(0x1_0000))
        .collect::<Result<Vec<_>, _>>()
        .unwrap();
}

Implementations§

Source§

impl<F> LzssEncoder<F>
where F: Fn(LzssCode, LzssCode) -> Ordering + Copy,

Source

pub fn new( comp: F, size_of_window: usize, max_match: usize, min_match: usize, lazy_level: usize, ) -> Self

Source

pub fn with_dict( comp: F, size_of_window: usize, max_match: usize, min_match: usize, lazy_level: usize, dict: &[u8], ) -> Self

Trait Implementations§

Source§

impl<F> Debug for LzssEncoder<F>
where F: Fn(LzssCode, LzssCode) -> Ordering + Copy + Debug,

Source§

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

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

impl<F> Encoder for LzssEncoder<F>
where F: Fn(LzssCode, LzssCode) -> Ordering + Copy,

Auto Trait Implementations§

§

impl<F> Freeze for LzssEncoder<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for LzssEncoder<F>
where F: RefUnwindSafe,

§

impl<F> Send for LzssEncoder<F>
where F: Send,

§

impl<F> Sync for LzssEncoder<F>
where F: Sync,

§

impl<F> Unpin for LzssEncoder<F>
where F: Unpin,

§

impl<F> UnwindSafe for LzssEncoder<F>
where F: UnwindSafe,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.