Skip to content

Commit 07ebd7c

Browse files
authored
Include huffman lookup table into binary (#188)
1 parent 8a9b57f commit 07ebd7c

File tree

2 files changed

+5
-83
lines changed

2 files changed

+5
-83
lines changed

src/parser/src/second_pass/huf.b

256 KB
Binary file not shown.

src/parser/src/second_pass/parser_settings.rs

+5-83
Original file line numberDiff line numberDiff line change
@@ -312,89 +312,11 @@ impl SpecialIDs {
312312
}
313313
}
314314

315-
fn msb(mut val: u32) -> u32 {
316-
let mut cnt = 0;
317-
while val > 0 {
318-
cnt = cnt + 1;
319-
val = val >> 1;
320-
}
321-
cnt
322-
}
323-
324315
pub fn create_huffman_lookup_table() -> Vec<(u8, u8)> {
325-
let mut huffman_table = vec![(255, 255); HUF_LOOKUPTABLE_MAXVALUE as usize];
326-
let mut huffman_rev_table = vec![(255, 255); HUF_LOOKUPTABLE_MAXVALUE as usize];
327-
328-
huffman_table[0] = (0, 1);
329-
huffman_table[2] = (39, 2);
330-
huffman_table[24] = (8, 5);
331-
huffman_table[50] = (2, 6);
332-
huffman_table[51] = (29, 6);
333-
huffman_table[100] = (2, 6);
334-
huffman_table[101] = (29, 6);
335-
huffman_table[26] = (4, 5);
336-
huffman_table[432] = (30, 9);
337-
huffman_table[866] = (38, 10);
338-
huffman_table[55488] = (35, 16);
339-
huffman_table[55489] = (34, 16);
340-
huffman_table[27745] = (27, 15);
341-
huffman_table[55492] = (25, 16);
342-
huffman_table[55493] = (24, 16);
343-
huffman_table[55494] = (33, 16);
344-
huffman_table[55495] = (28, 16);
345-
huffman_table[55496] = (13, 16);
346-
huffman_table[110994] = (15, 17);
347-
huffman_table[110995] = (14, 17);
348-
huffman_table[27749] = (6, 15);
349-
huffman_table[111000] = (21, 17);
350-
huffman_table[111001] = (20, 17);
351-
huffman_table[111002] = (23, 17);
352-
huffman_table[111003] = (22, 17);
353-
huffman_table[111004] = (17, 17);
354-
huffman_table[111005] = (16, 17);
355-
huffman_table[111006] = (19, 17);
356-
huffman_table[111007] = (18, 17);
357-
huffman_table[3469] = (5, 12);
358-
huffman_table[1735] = (36, 11);
359-
huffman_table[217] = (10, 8);
360-
huffman_table[218] = (7, 8);
361-
huffman_table[438] = (12, 9);
362-
huffman_table[439] = (37, 9);
363-
huffman_table[220] = (9, 8);
364-
huffman_table[442] = (31, 9);
365-
huffman_table[443] = (26, 9);
366-
huffman_table[222] = (32, 8);
367-
huffman_table[223] = (3, 8);
368-
huffman_table[14] = (1, 4);
369-
huffman_table[15] = (11, 4);
370-
huffman_table[0] = (255, 255);
371-
372-
const RIGHTSHIFT_BITORDER: u32 = 64 - 17;
373-
let mut v: Vec<u32> = vec![];
374-
for (idx, x) in huffman_table.iter().enumerate() {
375-
if x.0 != 255 {
376-
v.push(idx as u32);
377-
}
378-
}
379-
let mut idx_msb_map = Vec::with_capacity(HUF_LOOKUPTABLE_MAXVALUE as usize);
380-
for i in 0..HUF_LOOKUPTABLE_MAXVALUE {
381-
idx_msb_map.push(msb(i));
382-
}
383-
for x in v {
384-
let shifta = msb(x);
385-
for (idx, pair) in idx_msb_map.iter().enumerate() {
386-
if x == idx as u32 >> pair.wrapping_sub(shifta) {
387-
let peekbits = (idx as u64).reverse_bits() >> RIGHTSHIFT_BITORDER;
388-
huffman_table[idx as usize] = huffman_table[x as usize];
389-
huffman_rev_table[peekbits as usize] = huffman_table[x as usize];
390-
}
391-
}
392-
}
393-
for v in 0..HUF_LOOKUPTABLE_MAXVALUE {
394-
let p: u64 = (v as u64).reverse_bits() >> RIGHTSHIFT_BITORDER;
395-
if p & 1 == 0 {
396-
huffman_rev_table[p as usize] = (0, 1);
397-
}
316+
let buf = include_bytes!("huf.b");
317+
let mut huf2 = Vec::with_capacity(HUF_LOOKUPTABLE_MAXVALUE as usize);
318+
for chunk in buf.chunks_exact(2) {
319+
huf2.push((chunk[0], chunk[1]));
398320
}
399-
huffman_rev_table
321+
return huf2;
400322
}

0 commit comments

Comments
 (0)