Skip to content

Commit

Permalink
Use unwrap_or (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm authored Dec 29, 2023
1 parent 2b31f65 commit f5c1afa
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/algorithms/lcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ where
d.equal(old_orig_idx, new_orig_idx, 1)?;
old_idx += 1;
new_idx += 1;
} else if table.get(&(new_idx, old_idx + 1)).map_or(0, |&x| x)
>= table.get(&(new_idx + 1, old_idx)).map_or(0, |&x| x)
} else if table.get(&(new_idx, old_idx + 1)).unwrap_or(&0)
>= table.get(&(new_idx + 1, old_idx)).unwrap_or(&0)
{
d.delete(old_orig_idx, 1, new_orig_idx)?;
old_idx += 1;
Expand Down Expand Up @@ -166,12 +166,12 @@ where

for j in (0..old_len).rev() {
let val = if new[i] == old[j] {
table.get(&(i + 1, j + 1)).map_or(0, |&x| x) + 1
table.get(&(i + 1, j + 1)).unwrap_or(&0) + 1
} else {
table
*table
.get(&(i + 1, j))
.map_or(0, |&x| x)
.max(table.get(&(i, j + 1)).map_or(0, |&x| x))
.unwrap_or(&0)
.max(table.get(&(i, j + 1)).unwrap_or(&0))
};
if val > 0 {
table.insert((i, j), val);
Expand Down

0 comments on commit f5c1afa

Please sign in to comment.