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>
impl<'huff, ValueType, D: TreeDegree> Decoder<'huff, ValueType, D>
Sourcepub fn consumed_fragments(&self) -> u32
pub fn consumed_fragments(&self) -> u32
Returns the number of fragments consumed since construction or last reset.
Sourcepub fn consume(&mut self, fragment: u32) -> DecodingResult<&'huff ValueType>
pub fn consume(&mut self, fragment: u32) -> DecodingResult<&'huff ValueType>
Consumes a fragment of the codeword and returns:
- a value if the given
fragmentfinishes the valid codeword; - an
DecodingResult::Incompleteif the codeword is incomplete and the next fragment is needed; - or
DecodingResult::Invalidif the codeword is invalid (possible only for bits per fragment > 1).
Result is undefined if fragment exceeds tree_degree.
Sourcepub fn consume_checked(
&mut self,
fragment: u32,
) -> DecodingResult<&'huff ValueType>
pub fn consume_checked( &mut self, fragment: u32, ) -> DecodingResult<&'huff ValueType>
Consumes a fragment of the codeword and returns:
- a value if the given
fragmentfinishes the valid codeword; - an
DecodingResult::Incompleteif the codeword is incomplete and the next fragment is needed; - or
DecodingResult::Invalidif the codeword is invalid (possible only fordegreegreater than 2) orfragmentis not less thandegree.
Sourcepub fn decode<F: Into<u32>, I: Iterator<Item = F>>(
&mut self,
fragments: &mut I,
) -> DecodingResult<&'huff ValueType>
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:
DecodingResult::Incompleteif the iterator exhausted before the value was decoded (Self::consumed_fragmentsenables checking if the iterator yielded any fragment before exhausting).DecodingResult::Invalidif obtained invalid codeword (possible only fordegreegreater than 2).
Sourcepub fn decode_next<F: Into<u32>, I: Iterator<Item = F>>(
&mut self,
fragments: &mut I,
) -> DecodingResult<&'huff ValueType>
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:
DecodingResult::Incompleteif the iterator exhausted before the value was decoded (Self::consumed_fragmentsenables checking if the iterator yielded any fragment before exhausting).DecodingResult::Invalidif obtained invalid codeword (possible only fordegreegreater than 2).