Struct constriction::stream::queue::RangeEncoder
source · pub struct RangeEncoder<Word, State, Backend = Vec<Word>>where
Word: BitArray,
State: BitArray,
Backend: WriteWords<Word>,{ /* private fields */ }Implementations§
source§impl<Word, State> RangeEncoder<Word, State>where
Word: BitArray + Into<State>,
State: BitArray + AsPrimitive<Word>,
impl<Word, State> RangeEncoder<Word, State>where
Word: BitArray + Into<State>,
State: BitArray + AsPrimitive<Word>,
source§impl<Word, State, Backend> RangeEncoder<Word, State, Backend>where
Word: BitArray + Into<State>,
State: BitArray + AsPrimitive<Word>,
Backend: WriteWords<Word>,
impl<Word, State, Backend> RangeEncoder<Word, State, Backend>where
Word: BitArray + Into<State>,
State: BitArray + AsPrimitive<Word>,
Backend: WriteWords<Word>,
sourcepub fn with_backend(backend: Backend) -> Self
pub fn with_backend(backend: Backend) -> Self
Assumes that the backend is in a state where the encoder can start writing as if
it was an empty backend. If there’s already some compressed data on backend, then
this method will just concatanate the new sequence of Words to the existing
sequence of Words without gluing them together. This is likely not what you want
since you won’t be able to decode the data in one go (however, it is Ok to
concatenate arbitrary data to the output of a RangeEncoder; it won’t invalidate
the existing data).
If you need an entropy coder that can be interrupted and serialized/deserialized
(i.e., an encoder that can encode some symbols, return the compressed bit string as
a sequence of Words, load the Words back in at a later point and then encode
some more symbols), then consider using an AnsCoder.
TODO: rename to with_write_backend and then add the same method to AnsCoder
sourcepub fn is_empty<'a>(&'a self) -> boolwhere
Backend: AsReadWords<'a, Word, Queue>,
Backend::AsReadWords: BoundedReadWords<Word, Queue>,
pub fn is_empty<'a>(&'a self) -> boolwhere
Backend: AsReadWords<'a, Word, Queue>,
Backend::AsReadWords: BoundedReadWords<Word, Queue>,
Check if no data has been encoded yet.
sourcepub fn maybe_full(&self) -> bool
pub fn maybe_full(&self) -> bool
Same as Encoder::maybe_full, but can be called on a concrete type without type
annotations.
sourcepub fn into_decoder(
self
) -> Result<RangeDecoder<Word, State, Backend::IntoReadWords>, ()>where
Backend: IntoReadWords<Word, Queue>,
pub fn into_decoder(
self
) -> Result<RangeDecoder<Word, State, Backend::IntoReadWords>, ()>where
Backend: IntoReadWords<Word, Queue>,
Same as IntoDecoder::into_decoder(self) but can be used for any PRECISION
and therefore doesn’t require type arguments on the caller side.
TODO: there should also be a decoder() method that takes &mut self
pub fn into_compressed(self) -> Result<Backend, Backend::WriteError>
sourcepub fn num_words<'a>(&'a self) -> usizewhere
Backend: AsReadWords<'a, Word, Queue>,
Backend::AsReadWords: BoundedReadWords<Word, Queue>,
pub fn num_words<'a>(&'a self) -> usizewhere
Backend: AsReadWords<'a, Word, Queue>,
Backend::AsReadWords: BoundedReadWords<Word, Queue>,
Returns the number of compressed words on the ans.
This includes a constant overhead of between one and two words unless the coder is completely empty.
This method returns the length of the slice, the Vec<Word>, or the iterator
that would be returned by get_compressed, into_compressed, or
iter_compressed, respectively, when called at this time.
See also num_bits.
sourcepub fn num_bits<'a>(&'a self) -> usizewhere
Backend: AsReadWords<'a, Word, Queue>,
Backend::AsReadWords: BoundedReadWords<Word, Queue>,
pub fn num_bits<'a>(&'a self) -> usizewhere
Backend: AsReadWords<'a, Word, Queue>,
Backend::AsReadWords: BoundedReadWords<Word, Queue>,
Returns the size of the current queue of compressed data in bits.
This includes some constant overhead unless the coder is completely empty
(see num_words).
The returned value is a multiple of the bitlength of the compressed word
type Word.
pub fn bulk(&self) -> &Backend
sourcepub fn from_raw_parts(
bulk: Backend,
state: RangeCoderState<Word, State>,
situation: EncoderSituation<Word>
) -> Self
pub fn from_raw_parts(
bulk: Backend,
state: RangeCoderState<Word, State>,
situation: EncoderSituation<Word>
) -> Self
Low-level constructor that assembles a RangeEncoder from its internal components.
The arguments bulk, state, and situation correspond to the three return values
of the method into_raw_parts.
sourcepub fn into_raw_parts(
self
) -> (Backend, RangeCoderState<Word, State>, EncoderSituation<Word>)
pub fn into_raw_parts(
self
) -> (Backend, RangeCoderState<Word, State>, EncoderSituation<Word>)
Low-level method that disassembles the RangeEncoder into its internal components.
Can be used together with from_raw_parts.
source§impl<Word, State> RangeEncoder<Word, State>where
Word: BitArray + Into<State>,
State: BitArray + AsPrimitive<Word>,
impl<Word, State> RangeEncoder<Word, State>where
Word: BitArray + Into<State>,
State: BitArray + AsPrimitive<Word>,
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Discards all compressed data and resets the coder to the same state as
Coder::new.
sourcepub fn get_compressed(&mut self) -> EncoderGuard<'_, Word, State>
pub fn get_compressed(&mut self) -> EncoderGuard<'_, Word, State>
Assembles the current compressed data into a single slice.
This method is only implemented for encoders backed by a Vec<Word>
because we have to temporarily seal the encoder and then unseal it when the returned
EncoderGuard is dropped, which requires precise knowledge of the backend (and
which is also the reason why this method takes a &mut self receiver). If you’re
using a different backend than a Vec, consider calling into_compressed
instead.
sourcepub fn decoder(
&mut self
) -> RangeDecoder<Word, State, Cursor<Word, EncoderGuard<'_, Word, State>>>
pub fn decoder(
&mut self
) -> RangeDecoder<Word, State, Cursor<Word, EncoderGuard<'_, Word, State>>>
A decoder for temporary use.
Once the returned decoder gets dropped, you can continue using this encoder. If you
don’t need this flexibility, call into_decoder instead.
This method is only implemented for encoders backed by a Vec<Word>
because we have to temporarily seal the encoder and then unseal it when the returned
decoder is dropped, which requires precise knowledge of the backend (and which is
also the reason why this method takes a &mut selfreceiver). If you’re using a
different backend than a Vec, consider calling into_decoder instead.
Trait Implementations§
source§impl<Word, State, Backend> Clone for RangeEncoder<Word, State, Backend>where
Word: BitArray + Clone,
State: BitArray + Clone,
Backend: WriteWords<Word> + Clone,
impl<Word, State, Backend> Clone for RangeEncoder<Word, State, Backend>where
Word: BitArray + Clone,
State: BitArray + Clone,
Backend: WriteWords<Word> + Clone,
source§fn clone(&self) -> RangeEncoder<Word, State, Backend>
fn clone(&self) -> RangeEncoder<Word, State, Backend>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<Word, State, Backend> Code for RangeEncoder<Word, State, Backend>where
Word: BitArray + Into<State>,
State: BitArray + AsPrimitive<Word>,
Backend: WriteWords<Word>,
impl<Word, State, Backend> Code for RangeEncoder<Word, State, Backend>where
Word: BitArray + Into<State>,
State: BitArray + AsPrimitive<Word>,
Backend: WriteWords<Word>,
§type State = RangeCoderState<Word, State>
type State = RangeCoderState<Word, State>
§type Word = Word
type Word = Word
Word per symbol (plus a constant
overhead).