/rust/registry/src/index.crates.io-1949cf8c6b5b557f/fax-0.2.7/src/maps.rs
Line | Count | Source |
1 | | use crate::{BitReader, Bits}; |
2 | | |
3 | | enum Entry<T: Copy + 'static> { |
4 | | Leaf(u8, &'static [Option<(T, u8)>]), |
5 | | Value(T, u8), |
6 | | Prefix(u8, &'static [Entry<T>]), |
7 | | } |
8 | | impl<T: Copy> Entry<T> { |
9 | 49.8k | fn find(&self, reader: &mut impl BitReader) -> Option<T> { |
10 | 49.8k | match *self { |
11 | 0 | Entry::Value(val, len) => { |
12 | 0 | reader.consume(len).ok()?; |
13 | 0 | Some(val) |
14 | | } |
15 | 6.24k | Entry::Leaf(width, lut) => { |
16 | 6.24k | let index = reader.peek(width)?; |
17 | 6.22k | let (val, len) = lut[index as usize]?; |
18 | 6.20k | reader.consume(len).ok()?; |
19 | 6.20k | Some(val) |
20 | | } |
21 | 43.6k | Entry::Prefix(width, lut) => { |
22 | 43.6k | let index = reader.peek(width)?; |
23 | 43.5k | let entry = &lut[index as usize]; |
24 | 43.5k | match *entry { |
25 | 37.2k | Entry::Value(val, len) => { |
26 | 37.2k | reader.consume(len).ok()?; |
27 | 37.2k | Some(val) |
28 | | } |
29 | | _ => { |
30 | 6.24k | reader.consume(width).ok()?; |
31 | 6.24k | entry.find(reader) |
32 | | } |
33 | | } |
34 | | } |
35 | | } |
36 | 49.8k | } <fax::maps::Entry<fax::maps::Mode>>::find::<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>> Line | Count | Source | 9 | 30.1k | fn find(&self, reader: &mut impl BitReader) -> Option<T> { | 10 | 30.1k | match *self { | 11 | 0 | Entry::Value(val, len) => { | 12 | 0 | reader.consume(len).ok()?; | 13 | 0 | Some(val) | 14 | | } | 15 | 0 | Entry::Leaf(width, lut) => { | 16 | 0 | let index = reader.peek(width)?; | 17 | 0 | let (val, len) = lut[index as usize]?; | 18 | 0 | reader.consume(len).ok()?; | 19 | 0 | Some(val) | 20 | | } | 21 | 30.1k | Entry::Prefix(width, lut) => { | 22 | 30.1k | let index = reader.peek(width)?; | 23 | 30.1k | let entry = &lut[index as usize]; | 24 | 30.1k | match *entry { | 25 | 30.1k | Entry::Value(val, len) => { | 26 | 30.1k | reader.consume(len).ok()?; | 27 | 30.1k | Some(val) | 28 | | } | 29 | | _ => { | 30 | 0 | reader.consume(width).ok()?; | 31 | 0 | entry.find(reader) | 32 | | } | 33 | | } | 34 | | } | 35 | | } | 36 | 30.1k | } |
<fax::maps::Entry<u16>>::find::<fax::ByteReader<std::io::Bytes<std::io::buffered::bufreader::BufReader<std::io::Take<&mut std::io::cursor::Cursor<&[u8]>>>>>> Line | Count | Source | 9 | 19.6k | fn find(&self, reader: &mut impl BitReader) -> Option<T> { | 10 | 19.6k | match *self { | 11 | 0 | Entry::Value(val, len) => { | 12 | 0 | reader.consume(len).ok()?; | 13 | 0 | Some(val) | 14 | | } | 15 | 6.24k | Entry::Leaf(width, lut) => { | 16 | 6.24k | let index = reader.peek(width)?; | 17 | 6.22k | let (val, len) = lut[index as usize]?; | 18 | 6.20k | reader.consume(len).ok()?; | 19 | 6.20k | Some(val) | 20 | | } | 21 | 13.4k | Entry::Prefix(width, lut) => { | 22 | 13.4k | let index = reader.peek(width)?; | 23 | 13.4k | let entry = &lut[index as usize]; | 24 | 13.4k | match *entry { | 25 | 7.17k | Entry::Value(val, len) => { | 26 | 7.17k | reader.consume(len).ok()?; | 27 | 7.17k | Some(val) | 28 | | } | 29 | | _ => { | 30 | 6.24k | reader.consume(width).ok()?; | 31 | 6.24k | entry.find(reader) | 32 | | } | 33 | | } | 34 | | } | 35 | | } | 36 | 19.6k | } |
Unexecuted instantiation: <fax::maps::Entry<_>>::find::<_> |
37 | | } |
38 | | |
39 | | pub const EDFB_HALF: Bits = Bits { data: 1, len: 12 }; |
40 | | pub const EOL: Bits = Bits { data: 1, len: 12 }; |
41 | | |
42 | | #[derive(Copy, Clone, Debug)] |
43 | | pub enum Mode { |
44 | | Pass, |
45 | | Horizontal, |
46 | | Vertical(i8), |
47 | | Extension, |
48 | | EOF, |
49 | | } |
50 | | |
51 | | #[cfg(feature="generate_bitmaps")] |
52 | | use fax_derive::bitmaps; |
53 | | |
54 | | #[cfg(feature="generate_bitmaps")] |
55 | | bitmaps! { |
56 | | mode <Mode> { |
57 | | 0001 => Mode::Pass, |
58 | | 001 => Mode::Horizontal, |
59 | | 1 => Mode::Vertical(0), |
60 | | 011 => Mode::Vertical(1), |
61 | | 000011 => Mode::Vertical(2), |
62 | | 0000011 => Mode::Vertical(3), |
63 | | 010 => Mode::Vertical(-1), |
64 | | 000010 => Mode::Vertical(-2), |
65 | | 0000010 => Mode::Vertical(-3), |
66 | | 0000001 => Mode::Extension, |
67 | | 000000000001 => Mode::EOF, |
68 | | }, |
69 | | black { |
70 | | 0000110111 => 0, |
71 | | 010 => 1, |
72 | | 11 => 2, |
73 | | 10 => 3, |
74 | | 011 => 4, |
75 | | 0011 => 5, |
76 | | 0010 => 6, |
77 | | 00011 => 7, |
78 | | 000101 => 8, |
79 | | 000100 => 9, |
80 | | 0000100 => 10, |
81 | | 0000101 => 11, |
82 | | 0000111 => 12, |
83 | | 00000100 => 13, |
84 | | 00000111 => 14, |
85 | | 000011000 => 15, |
86 | | 0000010111 => 16, |
87 | | 0000011000 => 17, |
88 | | 0000001000 => 18, |
89 | | 00001100111 => 19, |
90 | | 00001101000 => 20, |
91 | | 00001101100 => 21, |
92 | | 00000110111 => 22, |
93 | | 00000101000 => 23, |
94 | | 00000010111 => 24, |
95 | | 00000011000 => 25, |
96 | | 000011001010 => 26, |
97 | | 000011001011 => 27, |
98 | | 000011001100 => 28, |
99 | | 000011001101 => 29, |
100 | | 000001101000 => 30, |
101 | | 000001101001 => 31, |
102 | | 000001101010 => 32, |
103 | | 000001101011 => 33, |
104 | | 000011010010 => 34, |
105 | | 000011010011 => 35, |
106 | | 000011010100 => 36, |
107 | | 000011010101 => 37, |
108 | | 000011010110 => 38, |
109 | | 000011010111 => 39, |
110 | | 000001101100 => 40, |
111 | | 000001101101 => 41, |
112 | | 000011011010 => 42, |
113 | | 000011011011 => 43, |
114 | | 000001010100 => 44, |
115 | | 000001010101 => 45, |
116 | | 000001010110 => 46, |
117 | | 000001010111 => 47, |
118 | | 000001100100 => 48, |
119 | | 000001100101 => 49, |
120 | | 000001010010 => 50, |
121 | | 000001010011 => 51, |
122 | | 000000100100 => 52, |
123 | | 000000110111 => 53, |
124 | | 000000111000 => 54, |
125 | | 000000100111 => 55, |
126 | | 000000101000 => 56, |
127 | | 000001011000 => 57, |
128 | | 000001011001 => 58, |
129 | | 000000101011 => 59, |
130 | | 000000101100 => 60, |
131 | | 000001011010 => 61, |
132 | | 000001100110 => 62, |
133 | | 000001100111 => 63, |
134 | | 0000001111 => 64, |
135 | | 000011001000 => 128, |
136 | | 000011001001 => 192, |
137 | | 000001011011 => 256, |
138 | | 000000110011 => 320, |
139 | | 000000110100 => 384, |
140 | | 000000110101 => 448, |
141 | | 0000001101100 => 512, |
142 | | 0000001101101 => 576, |
143 | | 0000001001010 => 640, |
144 | | 0000001001011 => 704, |
145 | | 0000001001100 => 768, |
146 | | 0000001001101 => 832, |
147 | | 0000001110010 => 896, |
148 | | 0000001110011 => 960, |
149 | | 0000001110100 => 1024, |
150 | | 0000001110101 => 1088, |
151 | | 0000001110110 => 1152, |
152 | | 0000001110111 => 1216, |
153 | | 0000001010010 => 1280, |
154 | | 0000001010011 => 1344, |
155 | | 0000001010100 => 1408, |
156 | | 0000001010101 => 1472, |
157 | | 0000001011010 => 1536, |
158 | | 0000001011011 => 1600, |
159 | | 0000001100100 => 1664, |
160 | | 0000001100101 => 1728, |
161 | | 00000001000 => 1792, |
162 | | 00000001100 => 1856, |
163 | | 00000001101 => 1920, |
164 | | 000000010010 => 1984, |
165 | | 000000010011 => 2048, |
166 | | 000000010100 => 2112, |
167 | | 000000010101 => 2176, |
168 | | 000000010110 => 2240, |
169 | | 000000010111 => 2304, |
170 | | 000000011100 => 2368, |
171 | | 000000011101 => 2432, |
172 | | 000000011110 => 2496, |
173 | | 000000011111 => 2560, |
174 | | }, |
175 | | white { |
176 | | 00110101 => 0, |
177 | | 000111 => 1, |
178 | | 0111 => 2, |
179 | | 1000 => 3, |
180 | | 1011 => 4, |
181 | | 1100 => 5, |
182 | | 1110 => 6, |
183 | | 1111 => 7, |
184 | | 10011 => 8, |
185 | | 10100 => 9, |
186 | | 00111 => 10, |
187 | | 01000 => 11, |
188 | | 001000 => 12, |
189 | | 000011 => 13, |
190 | | 110100 => 14, |
191 | | 110101 => 15, |
192 | | 101010 => 16, |
193 | | 101011 => 17, |
194 | | 0100111 => 18, |
195 | | 0001100 => 19, |
196 | | 0001000 => 20, |
197 | | 0010111 => 21, |
198 | | 0000011 => 22, |
199 | | 0000100 => 23, |
200 | | 0101000 => 24, |
201 | | 0101011 => 25, |
202 | | 0010011 => 26, |
203 | | 0100100 => 27, |
204 | | 0011000 => 28, |
205 | | 00000010 => 29, |
206 | | 00000011 => 30, |
207 | | 00011010 => 31, |
208 | | 00011011 => 32, |
209 | | 00010010 => 33, |
210 | | 00010011 => 34, |
211 | | 00010100 => 35, |
212 | | 00010101 => 36, |
213 | | 00010110 => 37, |
214 | | 00010111 => 38, |
215 | | 00101000 => 39, |
216 | | 00101001 => 40, |
217 | | 00101010 => 41, |
218 | | 00101011 => 42, |
219 | | 00101100 => 43, |
220 | | 00101101 => 44, |
221 | | 00000100 => 45, |
222 | | 00000101 => 46, |
223 | | 00001010 => 47, |
224 | | 00001011 => 48, |
225 | | 01010010 => 49, |
226 | | 01010011 => 50, |
227 | | 01010100 => 51, |
228 | | 01010101 => 52, |
229 | | 00100100 => 53, |
230 | | 00100101 => 54, |
231 | | 01011000 => 55, |
232 | | 01011001 => 56, |
233 | | 01011010 => 57, |
234 | | 01011011 => 58, |
235 | | 01001010 => 59, |
236 | | 01001011 => 60, |
237 | | 00110010 => 61, |
238 | | 00110011 => 62, |
239 | | 00110100 => 63, |
240 | | 11011 => 64, |
241 | | 10010 => 128, |
242 | | 010111 => 192, |
243 | | 0110111 => 256, |
244 | | 00110110 => 320, |
245 | | 00110111 => 384, |
246 | | 01100100 => 448, |
247 | | 01100101 => 512, |
248 | | 01101000 => 576, |
249 | | 01100111 => 640, |
250 | | 011001100 => 704, |
251 | | 011001101 => 768, |
252 | | 011010010 => 832, |
253 | | 011010011 => 896, |
254 | | 011010100 => 960, |
255 | | 011010101 => 1024, |
256 | | 011010110 => 1088, |
257 | | 011010111 => 1152, |
258 | | 011011000 => 1216, |
259 | | 011011001 => 1280, |
260 | | 011011010 => 1344, |
261 | | 011011011 => 1408, |
262 | | 010011000 => 1472, |
263 | | 010011001 => 1536, |
264 | | 010011010 => 1600, |
265 | | 011000 => 1664, |
266 | | 010011011 => 1728, |
267 | | 00000001000 => 1792, |
268 | | 00000001100 => 1856, |
269 | | 00000001101 => 1920, |
270 | | 000000010010 => 1984, |
271 | | 000000010011 => 2048, |
272 | | 000000010100 => 2112, |
273 | | 000000010101 => 2176, |
274 | | 000000010110 => 2240, |
275 | | 000000010111 => 2304, |
276 | | 000000011100 => 2368, |
277 | | 000000011101 => 2432, |
278 | | 000000011110 => 2496, |
279 | | 000000011111 => 2560, |
280 | | }, |
281 | | } |
282 | | |
283 | | #[cfg(not(feature="generate_bitmaps"))] |
284 | | include!("bitmaps.rs"); |