heyimalex / bitap

Fuzzy string search algorithm in Rust
9 stars 0 forks source link

Issue with matching at the start #1

Closed heyimalex closed 5 years ago

heyimalex commented 5 years ago

Text that starts with a match doesn't work correctly right now, ex a pattern of "abc" fails to match at "bc" with an edit distance of 1, even though it's just one insertion away. This still works with places that aren't exactly at the start, so it's not an issue with recognizing insertions so much as the initial state of the machine not taking them into account. I think this can be fixed by initializing r with this code.

for (i, rv) in r.iter_mut().enumerate() {
    *rv <<= i;
}

This brings up a larger issue with test coverage and the "reference" implementation, which in this case is also flawed. I need to add a whole lot of tests and also need to make the reference implementation more simple. Bitap can be thought of as exhaustively checking levenshtein distance of the pattern from every substring of the text, so maybe the "reference" function should go that longer/slower way instead of just testing that my flawed impl works?

heyimalex commented 5 years ago

Closed via initial release re-write!