fastqc_rust/utils/base_counts.rs
1/// Lookup table: maps ASCII byte to base index.
2/// 0=A, 1=C, 2=G, 3=T, 4=N, 5=other
3///
4/// Using a lookup table instead of match/if-else eliminates branch misprediction
5/// on random DNA data (where each branch has ~25% probability, the worst case
6/// for branch predictors).
7pub const BASE_INDEX: [u8; 256] = {
8 let mut table = [5u8; 256];
9 table[b'A' as usize] = 0;
10 table[b'C' as usize] = 1;
11 table[b'G' as usize] = 2;
12 table[b'T' as usize] = 3;
13 table[b'N' as usize] = 4;
14 table
15};
16
17/// Index constants for readability.
18pub const IDX_A: usize = 0;
19pub const IDX_C: usize = 1;
20pub const IDX_G: usize = 2;
21pub const IDX_T: usize = 3;
22pub const IDX_N: usize = 4;