use crate::core::util::automation::levenshtein_automata;
use crate::core::util::automation::levenshtein_automata::{
ParametricDescription, ParametricDescriptionBase,
};
pub(crate) struct Lev1TParametricDescription;
pub(crate) fn new(w: i32) -> ParametricDescription {
ParametricDescription::new(w, 1, &[0, 1, 0, -1, -1, -1], Lev1TParametricDescription)
}
impl ParametricDescriptionBase for Lev1TParametricDescription {
fn transition(
&self,
abs_state: i32,
position: i32,
vector: i32,
base: &ParametricDescription,
) -> i32 {
debug_assert_ne!(abs_state, -1);
let mut state = abs_state / (base.w + 1);
let mut offset = abs_state % (base.w + 1);
debug_assert!(offset >= 0);
if position == base.w {
if state < 2 {
let loc = vector * 2 + state;
offset += levenshtein_automata::unpack(&OFFSET_INCRS_0, loc, 1);
state = levenshtein_automata::unpack(&TO_STATES_0, loc, 2) - 1;
}
} else if position == base.w - 1 {
if state < 3 {
let loc = vector * 3 + state;
offset += levenshtein_automata::unpack(&OFFSET_INCRS_1, loc, 1);
state = levenshtein_automata::unpack(&TO_STATES_1, loc, 2) - 1;
}
} else if position == base.w - 2 {
if state < 6 {
let loc = vector * 6 + state;
offset += levenshtein_automata::unpack(&OFFSET_INCRS_2, loc, 2);
state = levenshtein_automata::unpack(&TO_STATES_2, loc, 3) - 1;
}
} else if state < 6 {
let loc = vector * 6 + state;
offset += levenshtein_automata::unpack(&OFFSET_INCRS_3, loc, 2);
state = levenshtein_automata::unpack(&TO_STATES_3, loc, 3) - 1;
}
if state == -1 {
-1
} else {
state * (base.w + 1) + offset
}
}
}
const TO_STATES_0: [i64; 1] = [0x2];
const OFFSET_INCRS_0: [i64; 1] = [0x0];
const TO_STATES_1: [i64; 1] = [0xa43];
const OFFSET_INCRS_1: [i64; 1] = [0x38];
const TO_STATES_2: [i64; 2] = [0xb45a491412180003u64 as i64, 0x69];
const OFFSET_INCRS_2: [i64; 1] = [0x5555558a0000];
const TO_STATES_3: [i64; 3] = [0xa1904864900c0003u64 as i64, 0x5a6d196a45a49169, 0x9634];
const OFFSET_INCRS_3: [i64; 2] = [0x5555ba08a0fc0000, 0x55555555];