first imml

This commit is contained in:
wiiznokes 2024-05-30 18:26:04 +02:00
parent 1a4a100266
commit 6017fc3913

View file

@ -79,6 +79,49 @@ pub fn app_id_or_fallback_matches(app_id: &str, entry: &DesktopEntryData) -> boo
|| app_id.to_lowercase() == entry.name.to_lowercase() || app_id.to_lowercase() == entry.name.to_lowercase()
} }
pub fn lcs(s1: &str, s2: &str) -> usize {
let mut mat: Vec<Vec<i32>> = vec![vec![0; s1.len() + 1]; s2.len() + 1];
for (i, u) in s1.char_indices() {
for (j, v) in s2.char_indices() {
if i == 0 || j == 0 {
mat[i][j] = 0;
} else if u == v {
mat[i][j] = mat[i - 1][j - 1] + 1;
} else {
mat[i][j] = max(mat[i - 1][j], mat[i][j - 1]);
}
}
}
let mut s1_iter = s1.char_indices().rev().peekable();
let mut s2_iter = s1.char_indices().rev().peekable();
let mut res = 0;
dbg!(&mat);
while let (Some((i, u)), Some((j, v))) = (s1_iter.peek(), s2_iter.peek()) {
if u == v {
res += 1;
s1_iter.next();
s2_iter.next();
} else if mat[i - 1][*j] > mat[*i][j - 1] {
s1_iter.next();
} else {
s2_iter.next();
}
}
println!("res = {res}");
res
}
/// lower is better /// lower is better
fn match_entry(id: &str, de: &DesktopEntry) -> f32 { fn match_entry(id: &str, de: &DesktopEntry) -> f32 {