Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finish is not always called in LCS algorithm #55

Closed
madsmtm opened this issue Dec 18, 2023 · 0 comments · Fixed by #58
Closed

finish is not always called in LCS algorithm #55

madsmtm opened this issue Dec 18, 2023 · 0 comments · Fixed by #58

Comments

@madsmtm
Copy link
Contributor

madsmtm commented Dec 18, 2023

The LCS implementation does not always call finish at the end of its execution. This can cause issues when used with diff hooks like Replace.

You can use the code below as a regression test.

use similar::algorithms::{lcs, DiffHook};

struct HasRunFinish(bool);

impl DiffHook for HasRunFinish {
    type Error = ();
    fn finish(&mut self) -> Result<(), Self::Error> {
        self.0 = true;
        Ok(())
    }
}

let mut d = HasRunFinish(false);
let slice = &[1, 2];
lcs::diff(&mut d, slice, 0..slice.len(), slice, 0..slice.len()).unwrap();
assert!(d.0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant