#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RansVariant {
RansByte,
Rans64,
}
impl RansVariant {
pub const fn state_size(&self) -> usize {
match self {
RansVariant::RansByte => 4,
RansVariant::Rans64 => 8,
}
}
pub const fn unit_size(&self) -> usize {
match self {
RansVariant::RansByte => 1,
RansVariant::Rans64 => 4,
}
}
}
pub trait RansParams {
type State: Copy + Clone + Default + core::fmt::Debug + PartialEq + Eq;
type Unit: Copy + Clone + Default + core::fmt::Debug + PartialEq + Eq;
const NAME: &'static str;
const STATE_BITS: u32;
const MAX_SCALE_BITS: u32;
const LOWER_BOUND: Self::State;
const UNIT_BITS: u32;
const UNITS_PER_STATE: usize;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RansByte;
impl RansParams for RansByte {
type State = u32;
type Unit = u8;
const NAME: &'static str = "RansByte";
const STATE_BITS: u32 = 31;
const MAX_SCALE_BITS: u32 = 30;
const LOWER_BOUND: u32 = 1u32 << 23;
const UNIT_BITS: u32 = 8;
const UNITS_PER_STATE: usize = 4;
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Rans64;
impl RansParams for Rans64 {
type State = u64;
type Unit = u32;
const NAME: &'static str = "Rans64";
const STATE_BITS: u32 = 63;
const MAX_SCALE_BITS: u32 = 32;
const LOWER_BOUND: u64 = 1u64 << 31;
const UNIT_BITS: u32 = 32;
const UNITS_PER_STATE: usize = 2;
}