Debian Codegraph @

src/internal.rs

raw symbols SCIP
1 pub(crate) mod ppmd7;
2
3 pub(crate) mod ppmd8;
4
5 mod tagged_offset;
6
7 pub(crate) use tagged_offset::*;
8
9 const PPMD_INT_BITS: u32 = 7;
10 const PPMD_PERIOD_BITS: u32 = 7;
11 const PPMD_BIN_SCALE: u32 = 1 << (PPMD_INT_BITS + PPMD_PERIOD_BITS);
12
13 const fn ppmd_get_mean_spec(summ: u32, shift: u32, round: u32) -> u32 {
14 (summ + (1 << (shift - round))) >> shift
15 }
16
17 const fn ppmd_get_mean(summ: u32) -> u32 {
18 ppmd_get_mean_spec(summ, PPMD_PERIOD_BITS, 2)
19 }
20
21 const fn ppmd_update_prob_1(prob: u32) -> u32 {
22 prob - ppmd_get_mean(prob)
23 }
24
25 const PPMD_N1: u32 = 4;
26 const PPMD_N2: u32 = 4;
27 const PPMD_N3: u32 = 4;
28 const PPMD_N4: u32 = (128 + 3 - PPMD_N1 - 2 * PPMD_N2 - 3 * PPMD_N3) / 4;
29 const PPMD_NUM_INDEXES: u32 = PPMD_N1 + PPMD_N2 + PPMD_N3 + PPMD_N4;
30
31 enum SeeSource {
32 Dummy,
33 Table(usize, usize),
34 }
35
36 #[derive(Copy, Clone, Default)]
37 #[repr(C, packed)]
38 struct See {
39 summ: u16,
40 shift: u8,
41 count: u8,
42 }
43
44 impl See {
45 fn update(&mut self) {
46 if (self.shift as i32) < 7 && {
47 self.count = self.count.wrapping_sub(1);
48 self.count as i32 == 0
49 } {
50 self.summ = ((self.summ as i32) << 1) as u16;
51 let fresh = self.shift;
52 self.shift = self.shift.wrapping_add(1);
53 self.count = (3 << fresh as i32) as u8;
54 }
55 }
56 }
57
58 #[derive(Copy, Clone)]
59 #[repr(C, packed)]
60 struct State {
61 symbol: u8,
62 freq: u8,
63 successor_0: u16,
64 successor_1: u16,
65 }
66
67 impl Pointee for State {
68 const TAG: u32 = TAG_STATE;
69 }
70
71 impl State {
72 fn set_successor(&mut self, v: TaggedOffset) {
73 let raw = v.as_raw();
74 self.successor_0 = raw as u16;
75 self.successor_1 = (raw >> 16) as u16;
76 }
77
78 fn get_successor(&self) -> TaggedOffset {
79 let raw = self.successor_0 as u32 + ((self.successor_1 as u32) << 16);
80 TaggedOffset::from_raw(raw)
81 }
82 }
83
84 #[derive(Copy, Clone)]
85 #[repr(C, packed)]
86 struct State2 {
87 symbol: u8,
88 freq: u8,
89 }
90
91 #[derive(Copy, Clone)]
92 #[repr(C, packed)]
93 struct State4 {
94 successor_0: u16,
95 successor_1: u16,
96 }
97
98 impl State4 {
99 fn set_successor(&mut self, v: TaggedOffset) {
100 let raw = v.as_raw();
101 self.successor_0 = raw as u16;
102 self.successor_1 = (raw >> 16) as u16;
103 }
104
105 fn get_successor(&self) -> TaggedOffset {
106 let raw = self.successor_0 as u32 + ((self.successor_1 as u32) << 16);
107 TaggedOffset::from_raw(raw)
108 }
109 }
110
111 #[derive(Copy, Clone)]
112 #[repr(C)]
113 union Union2 {
114 summ_freq: u16,
115 state2: State2,
116 }
117
118 #[derive(Copy, Clone)]
119 #[repr(C)]
120 union Union4 {
121 stats: TaggedOffset,
122 state4: State4,
123 }