first imml
This commit is contained in:
parent
c2b475b436
commit
cb42c7d71f
1 changed files with 43 additions and 0 deletions
|
|
@ -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 {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue