use core::borrow::Borrow;
use ts_bitset::Bitset256;
use crate::base_index::BaseIndex;
#[inline]
pub const fn lookup(index: BaseIndex) -> impl Borrow<Bitset256> + 'static {
cfg_if::cfg_if! {
if #[cfg(feature = "lut")] {
&LUT[index.get() as usize]
} else {
lpm_entry(index.get())
}
}
}
const fn lpm_entry(i: u8) -> Bitset256 {
let mut entry = Bitset256::EMPTY;
let mut j = i;
while j > 0 {
entry.set(j as _);
j = j.unbounded_shr(1);
}
entry
}
#[cfg(feature = "lut")]
static LUT: [Bitset256; 256] = {
let mut ret = [Bitset256::EMPTY; 256];
let mut i = 1usize;
while i < ret.len() {
ret[i] = lpm_entry(i as u8);
i += 1;
}
ret
};
#[cfg(feature = "lut")]
pub const LUT_SIZE: usize = size_of_val(&LUT);