Type Alias constriction::stream::model::SmallContiguousLookupDecoderModel
source · pub type SmallContiguousLookupDecoderModel<SymbolTable = Vec<u16>, LookupTable = Box<[u16]>> = LookupDecoderModel<usize, u16, ContiguousSymbolTable<SymbolTable>, LookupTable, 12>;
Expand description
Type alias for a LookupDecoderModel
over symbols {0, 1, ..., n-1}
with sane settings.
This array lookup table can be used with a SmallAnsCoder
or a SmallRangeDecoder
(as well as with a DefaultAnsCoder
or a DefaultRangeDecoder
, since you can
always use a “bigger” coder on a “smaller” model).
Example
Decoding a sequence of symbols with a SmallAnsCoder
, a DefaultAnsCoder
, a
SmallRangeDecoder
, and a DefaultRangeDecoder
, all using the same
SmallContiguousLookupDecoderModel
.
use constriction::stream::{
model::SmallContiguousLookupDecoderModel,
stack::{SmallAnsCoder, DefaultAnsCoder},
queue::{SmallRangeDecoder, DefaultRangeDecoder},
Decode, Code,
};
// Create a `SmallContiguousLookupDecoderModel` from a probability distribution that's already
// available in fixed point representation (e.g., because it was deserialized from a file).
// Alternatively, we could use `from_floating_point_probabilities_contiguous`.
let probabilities = [1489, 745, 1489, 373];
let decoder_model = SmallContiguousLookupDecoderModel
::from_nonzero_fixed_point_probabilities_contiguous(&probabilities, false).unwrap();
let expected = [2, 1, 3, 0, 0, 2, 0, 2, 1, 0, 2];
let mut small_ans_coder = SmallAnsCoder::from_compressed(vec![0xDA86, 0x2949]).unwrap();
let reconstructed = small_ans_coder
.decode_iid_symbols(11, &decoder_model).collect::<Result<Vec<_>, _>>().unwrap();
assert!(small_ans_coder.is_empty());
assert_eq!(reconstructed, expected);
let mut default_ans_decoder = DefaultAnsCoder::from_compressed(vec![0x2949DA86]).unwrap();
let reconstructed = default_ans_decoder
.decode_iid_symbols(11, &decoder_model).collect::<Result<Vec<_>, _>>().unwrap();
assert!(default_ans_decoder.is_empty());
assert_eq!(reconstructed, expected);
let mut small_range_decoder = SmallRangeDecoder::from_compressed(vec![0xBCF8, 0x3ECA]).unwrap();
let reconstructed = small_range_decoder
.decode_iid_symbols(11, &decoder_model).collect::<Result<Vec<_>, _>>().unwrap();
assert!(small_range_decoder.maybe_exhausted());
assert_eq!(reconstructed, expected);
let mut default_range_decoder = DefaultRangeDecoder::from_compressed(vec![0xBCF8733B]).unwrap();
let reconstructed = default_range_decoder
.decode_iid_symbols(11, &decoder_model).collect::<Result<Vec<_>, _>>().unwrap();
assert!(default_range_decoder.maybe_exhausted());
assert_eq!(reconstructed, expected);
See also
Aliased Type§
struct SmallContiguousLookupDecoderModel<SymbolTable = Vec<u16>, LookupTable = Box<[u16]>> { /* private fields */ }