use super::table::{ASCII_PRIMARY, ASCII_TERTIARY};
pub(super) fn compare_ascii(a: &[u16], b: &[u16]) -> f64 {
let weights = |s: &[u16], table: &[u8; 128]| -> Vec<u8> {
s.iter()
.filter(|&&c| ASCII_PRIMARY[c as usize] != 0)
.map(|&c| table[c as usize])
.collect()
};
let order = weights(a, &ASCII_PRIMARY)
.cmp(&weights(b, &ASCII_PRIMARY))
.then_with(|| weights(a, &ASCII_TERTIARY).cmp(&weights(b, &ASCII_TERTIARY)));
match order {
std::cmp::Ordering::Less => -1.0,
std::cmp::Ordering::Equal => 0.0,
std::cmp::Ordering::Greater => 1.0,
}
}