A generic and fast implementation of the Levenshtein distance.
This crate can work on slices of any kind. It can therefore:
rust
assert_eq!(distance ("abc", "aaxcc"), 3);
rust
assert_eq!(
distance (
"The quick brown fox".split (' ').collect::<Vec<_>>(),
"The very quick brown cat".split (' ').collect()),
2);
rust
assert_eq!(distance (vec![1, 2, 3], vec![0, 1, 3, 3, 4]), 3);
At the time of writing, this crate is the fastest on crates.io when
working with text (on par with eddie
):
| | Identical | Same length | Different lengths | |:-----------------------------------------------------------|----------:|------------:|------------------:| | genericlevenshtein | 3 | 9616 | 11010 | | levenshtein v1.0.4 | 4 | 11030 | 12777 | | strsim v0.9.2 | 9173 | 10100 | 11738 | | distance v0.4.0 | 23594 | 13800 | 26890 | | eddie v0.3.2 | 215 | 7464 | 11968 | | txtdist v0.2.1 | 17732 | 17635 | 20975 |
All times in ns
on an Intel(R) Core(TM) i5-4300M CPU @ 2.60GHz
.