// ENC: ASCII byte → 2-bit nucleotide code (A=0, C=1, G=2, T/U=3).
// Indexed by b & 0x1F — 32 entries, handles upper/lowercase identically,
// ambiguous bases and unknowns silently map to A (0).
pub(crate) static ENC: [u8; 32] = [
//  _   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O
    0,  0,  0,  1,  0,  0,  0,  2,  0,  0,  0,  0,  0,  0,  0,  0,
//  P   Q   R   S   T   U   V   W   X   Y   Z  ...
    0,  0,  0,  0,  3,  3,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
];

// DEC4: packed byte → 4 ASCII nucleotides encoded as big-endian u32.
// DEC4[b].to_be_bytes() == [nuc0, nuc1, nuc2, nuc3] where nuc0 is at the MSB of b.
pub(crate) static DEC4: [u32; 256] = build_dec4();

pub(crate) fn encode_base(b: u8) -> u8 {
    ENC[(b & 0x1F) as usize]
}

const fn build_dec4() -> [u32; 256] {
    const DECODE: [u8; 4] = [b'A', b'C', b'G', b'T'];
    let mut table = [0u32; 256];
    let mut i = 0usize;
    while i < 256 {
        table[i] = (DECODE[(i >> 6) & 3] as u32) << 24
                 | (DECODE[(i >> 4) & 3] as u32) << 16
                 | (DECODE[(i >> 2) & 3] as u32) << 8
                 |  DECODE[i & 3] as u32;
        i += 1;
    }
    table
}
