Decoder

Struct Decoder 

Source
pub struct Decoder<'huff, ValueType, D = BitsPerFragment> { /* private fields */ }
Expand description

Decoder that decodes a value for given code, consuming one codeword fragment (and going one level down the huffman tree) at a time.

Time complexity of decoding the whole code is:

  • pessimistic: O(length of the longest code)
  • expected: O(log(number of values, i.e. length of coding.values))
  • optimistic: O(1)

Memory complexity: O(1)

Implementations§

Source§

impl<'huff, ValueType, D: TreeDegree> Decoder<'huff, ValueType, D>

Source

pub fn new(coding: &'huff Coding<ValueType, D>) -> Self

Constructs decoder for given coding.

Source

pub fn reset(&mut self)

Resets self to initial state and makes it ready to decode next value.

Source

pub fn consumed_fragments(&self) -> u32

Returns the number of fragments consumed since construction or last reset.

Source

pub fn consume(&mut self, fragment: u32) -> DecodingResult<&'huff ValueType>

Consumes a fragment of the codeword and returns:

  • a value if the given fragment finishes the valid codeword;
  • an DecodingResult::Incomplete if the codeword is incomplete and the next fragment is needed;
  • or DecodingResult::Invalid if the codeword is invalid (possible only for bits per fragment > 1).

Result is undefined if fragment exceeds tree_degree.

Source

pub fn consume_checked( &mut self, fragment: u32, ) -> DecodingResult<&'huff ValueType>

Consumes a fragment of the codeword and returns:

  • a value if the given fragment finishes the valid codeword;
  • an DecodingResult::Incomplete if the codeword is incomplete and the next fragment is needed;
  • or DecodingResult::Invalid if the codeword is invalid (possible only for degree greater than 2) or fragment is not less than degree.
Source

pub fn decode<F: Into<u32>, I: Iterator<Item = F>>( &mut self, fragments: &mut I, ) -> DecodingResult<&'huff ValueType>

Tries to decode and return a single value from the fragments iterator, consuming as many fragments as needed.

To decode the next value, self must be reset first (see also Self::decode_next).

In case of failure, returns:

Source

pub fn decode_next<F: Into<u32>, I: Iterator<Item = F>>( &mut self, fragments: &mut I, ) -> DecodingResult<&'huff ValueType>

Tries to decode and return a single value from the fragments iterator, consuming as many fragments as needed.

If successful, it resets self to be ready to decode the next value (see also Self::decode).

In case of failure, returns:

Auto Trait Implementations§

§

impl<'huff, ValueType, D> Freeze for Decoder<'huff, ValueType, D>

§

impl<'huff, ValueType, D> RefUnwindSafe for Decoder<'huff, ValueType, D>
where D: RefUnwindSafe, ValueType: RefUnwindSafe,

§

impl<'huff, ValueType, D> Send for Decoder<'huff, ValueType, D>
where D: Sync, ValueType: Sync,

§

impl<'huff, ValueType, D> Sync for Decoder<'huff, ValueType, D>
where D: Sync, ValueType: Sync,

§

impl<'huff, ValueType, D> Unpin for Decoder<'huff, ValueType, D>

§

impl<'huff, ValueType, D> UnwindSafe for Decoder<'huff, ValueType, D>
where D: RefUnwindSafe, ValueType: RefUnwindSafe,

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.