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>,

source

pub fn new() -> Self

Creates an empty encoder for range coding.

source§

impl<Word, State, Backend> RangeEncoder<Word, State, Backend>
where Word: BitArray + Into<State>, State: BitArray + AsPrimitive<Word>, Backend: WriteWords<Word>,

source

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

source

pub fn is_empty<'a>(&'a self) -> bool
where Backend: AsReadWords<'a, Word, Queue>, Backend::AsReadWords: BoundedReadWords<Word, Queue>,

Check if no data has been encoded yet.

source

pub fn maybe_full(&self) -> bool

Same as Encoder::maybe_full, but can be called on a concrete type without type annotations.

source

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

source

pub fn into_compressed(self) -> Result<Backend, Backend::WriteError>

source

pub fn num_words<'a>(&'a self) -> usize
where 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.

source

pub fn num_bits<'a>(&'a self) -> usize
where 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.

source

pub fn bulk(&self) -> &Backend

source

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.

source

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>,

source

pub fn clear(&mut self)

Discards all compressed data and resets the coder to the same state as Coder::new.

source

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.

source

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,

source§

fn clone(&self) -> RangeEncoder<Word, State, Backend>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

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>

The internal coder state, as returned by the method state. Read more
§

type Word = Word

The smallest unit of compressed data that this coder can emit or read at once. Most coders guarantee that encoding emits at most one Word per symbol (plus a constant overhead).
source§

fn state(&self) -> Self::State

Returns the current internal state of the coder. Read more
source§

fn encoder_maybe_full<const PRECISION: usize>(&self) -> bool
where Self: Encode<PRECISION>,

Checks if there might not be any room to encode more data. Read more
source§

fn decoder_maybe_exhausted<const PRECISION: usize>(&self) -> bool
where Self: Decode<PRECISION>,

Checks if there might be no compressed data left for decoding. Read more
source§

impl<Word, State, Backend> Debug for RangeEncoder<Word, State, Backend>
where Word: BitArray + Debug, State: BitArray + Debug, Backend: WriteWords<Word> + Debug,

source§

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

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

impl<Word, State, Backend> Default for RangeEncoder<Word, State, Backend>
where Word: BitArray + Into<State>, State: BitArray + AsPrimitive<Word>, Backend: WriteWords<Word> + Default,

source§

fn default() -> Self

This is essentially the same as #[derive(Default)], except for the assertions on State::BITS and Word::BITS.

source§

impl<Word, State, Backend, const PRECISION: usize> Encode<PRECISION> for RangeEncoder<Word, State, Backend>
where Word: BitArray + Into<State>, State: BitArray + AsPrimitive<Word>, Backend: WriteWords<Word>,

§

type FrontendError = DefaultEncoderFrontendError

The error type for logical encoding errors. Read more
§

type BackendError = <Backend as WriteWords<Word>>::WriteError

The error type for writing out encoded data. Read more
source§

fn encode_symbol<D>( &mut self, symbol: impl Borrow<D::Symbol>, model: D ) -> Result<(), CoderError<DefaultEncoderFrontendError, Self::BackendError>>
where D: EncoderModel<PRECISION>, D::Probability: Into<Self::Word>, Self::Word: AsPrimitive<D::Probability>,

Encodes a single symbol with the given entropy model. Read more
source§

fn maybe_full(&self) -> bool

Checks if there might not be any room to encode more data. Read more
source§

fn encode_symbols<S, M>( &mut self, symbols_and_models: impl IntoIterator<Item = (S, M)> ) -> Result<(), CoderError<Self::FrontendError, Self::BackendError>>
where S: Borrow<M::Symbol>, M: EncoderModel<PRECISION>, M::Probability: Into<Self::Word>, Self::Word: AsPrimitive<M::Probability>,

Encodes a sequence of symbols, each with its individual entropy model. Read more
source§

fn try_encode_symbols<S, M, E>( &mut self, symbols_and_models: impl IntoIterator<Item = Result<(S, M), E>> ) -> Result<(), TryCodingError<CoderError<Self::FrontendError, Self::BackendError>, E>>
where S: Borrow<M::Symbol>, M: EncoderModel<PRECISION>, M::Probability: Into<Self::Word>, Self::Word: AsPrimitive<M::Probability>,

Encodes a sequence of symbols from a fallible iterator. Read more
source§

fn encode_iid_symbols<S, M>( &mut self, symbols: impl IntoIterator<Item = S>, model: M ) -> Result<(), CoderError<Self::FrontendError, Self::BackendError>>
where S: Borrow<M::Symbol>, M: EncoderModel<PRECISION> + Copy, M::Probability: Into<Self::Word>, Self::Word: AsPrimitive<M::Probability>,

Encodes a sequence of symbols, all with the same entropy model. Read more
source§

impl<Word, State> From<RangeEncoder<Word, State>> for Vec<Word>
where Word: BitArray + Into<State>, State: BitArray + AsPrimitive<Word>,

source§

fn from(val: RangeEncoder<Word, State>) -> Self

Converts to this type from the input type.
source§

impl<Word, State, Backend> From<RangeEncoder<Word, State, Backend>> for RangeDecoder<Word, State, Backend::IntoReadWords>
where Word: BitArray + Into<State>, State: BitArray + AsPrimitive<Word>, Backend: WriteWords<Word> + IntoReadWords<Word, Queue>,

source§

fn from(encoder: RangeEncoder<Word, State, Backend>) -> Self

Converts to this type from the input type.
source§

impl<Word, State, Backend, const PRECISION: usize> IntoDecoder<PRECISION> for RangeEncoder<Word, State, Backend>
where Word: BitArray + Into<State>, State: BitArray + AsPrimitive<Word>, Backend: WriteWords<Word> + IntoReadWords<Word, Queue>,

§

type IntoDecoder = RangeDecoder<Word, State, <Backend as IntoReadWords<Word, Queue>>::IntoReadWords>

The target type of the conversion.
source§

fn into_decoder(self) -> Self::IntoDecoder

Performs the conversion.
source§

impl<Word, State, Backend> Pos for RangeEncoder<Word, State, Backend>
where Word: BitArray + Into<State>, State: BitArray + AsPrimitive<Word>, Backend: WriteWords<Word> + Pos<Position = usize>,

source§

fn pos(&self) -> Self::Position

Returns the position in the compressed data, in units of Words. Read more
source§

impl<Word, State, Backend> PosSeek for RangeEncoder<Word, State, Backend>
where Word: BitArray, State: BitArray, Backend: WriteWords<Word> + PosSeek, Self: Code,

§

type Position = (<Backend as PosSeek>::Position, <RangeEncoder<Word, State, Backend> as Code>::State)

Auto Trait Implementations§

§

impl<Word, State, Backend> RefUnwindSafe for RangeEncoder<Word, State, Backend>
where Backend: RefUnwindSafe, State: RefUnwindSafe, Word: RefUnwindSafe, <State as BitArray>::NonZero: RefUnwindSafe,

§

impl<Word, State, Backend> Send for RangeEncoder<Word, State, Backend>
where Backend: Send, State: Send, Word: Send, <State as BitArray>::NonZero: Send,

§

impl<Word, State, Backend> Sync for RangeEncoder<Word, State, Backend>
where Backend: Sync, State: Sync, Word: Sync, <State as BitArray>::NonZero: Sync,

§

impl<Word, State, Backend> Unpin for RangeEncoder<Word, State, Backend>
where Backend: Unpin, State: Unpin, Word: Unpin, <State as BitArray>::NonZero: Unpin,

§

impl<Word, State, Backend> UnwindSafe for RangeEncoder<Word, State, Backend>
where Backend: UnwindSafe, State: UnwindSafe, Word: UnwindSafe, <State as BitArray>::NonZero: 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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.