msrtc_rans_core/
variant.rs1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub enum RansVariant {
13 RansByte,
15 Rans64,
17}
18
19impl RansVariant {
20 pub const fn state_size(&self) -> usize {
22 match self {
23 RansVariant::RansByte => 4,
24 RansVariant::Rans64 => 8,
25 }
26 }
27
28 pub const fn unit_size(&self) -> usize {
30 match self {
31 RansVariant::RansByte => 1,
32 RansVariant::Rans64 => 4,
33 }
34 }
35}
36
37pub trait RansParams {
39 type State: Copy + Clone + Default + core::fmt::Debug + PartialEq + Eq;
41 type Unit: Copy + Clone + Default + core::fmt::Debug + PartialEq + Eq;
43 const NAME: &'static str;
45 const STATE_BITS: u32;
47 const MAX_SCALE_BITS: u32;
49 const LOWER_BOUND: Self::State;
51 const UNIT_BITS: u32;
53 const UNITS_PER_STATE: usize;
55}
56
57#[derive(Debug, Clone, Copy, PartialEq, Eq)]
59pub struct RansByte;
60
61impl RansParams for RansByte {
62 type State = u32;
63 type Unit = u8;
64 const NAME: &'static str = "RansByte";
65 const STATE_BITS: u32 = 31;
66 const MAX_SCALE_BITS: u32 = 30;
67 const LOWER_BOUND: u32 = 1u32 << 23;
68 const UNIT_BITS: u32 = 8;
69 const UNITS_PER_STATE: usize = 4;
70}
71
72#[derive(Debug, Clone, Copy, PartialEq, Eq)]
74pub struct Rans64;
75
76impl RansParams for Rans64 {
77 type State = u64;
78 type Unit = u32;
79 const NAME: &'static str = "Rans64";
80 const STATE_BITS: u32 = 63;
81 const MAX_SCALE_BITS: u32 = 32;
82 const LOWER_BOUND: u64 = 1u64 << 31;
83 const UNIT_BITS: u32 = 32;
84 const UNITS_PER_STATE: usize = 2;
85}