### 5 unstable releases

✓ Uses Rust 2018 edition

new 0.3.1 | Dec 10, 2019 |
---|---|

0.2.2 | Dec 1, 2019 |

0.2.1 | Mar 17, 2019 |

0.2.0 | Mar 4, 2019 |

0.1.0 | Mar 2, 2019 |

#**59** in Text processing

**649** downloads per month

Used in **8** crates (3 directly)

**MIT**license

55KB

1K
SLoC

# Fuzzy Matcher

Fuzzy matching algorithm(s) in Rust!

## Usage

In your Cargo.toml add the following:

`[``dependencies``]`
`fuzzy-matcher ``=` `"`*`"`

Here are some code example:

`use` `fuzzy_matcher``::`FuzzyMatcher`;`
`use` `fuzzy_matcher``::``skim``::`SkimMatcherV2`;`
`let` matcher `=` `SkimMatcherV2``::`default`(``)``;`
`assert_eq!``(``None``,` matcher`.``fuzzy_match``(``"`abc`"``,` `"`abx`"``)``)``;`
`assert!``(`matcher`.``fuzzy_match``(``"`axbycz`"``,` `"`abc`"``)``.``is_some``(``)``)``;`
`assert!``(`matcher`.``fuzzy_match``(``"`axbycz`"``,` `"`xyz`"``)``.``is_some``(``)``)``;`
`let` `(`score`,` indices`)` `=` matcher`.``fuzzy_indices``(``"`axbycz`"``,` `"`abc`"``)``.``unwrap``(``)``;`
`assert_eq!``(`indices`,` `[``0``,` `2``,` `4``]``)``;`

only return scores while`fuzzy_match`

returns the matching indices as well.`fuzzy_indices`- Both function return None if the pattern won't match.
- The score is the higher the better.

## More example

and check what happens.`echo "axbycz" | cargo run --example fz "abc"`

## About the Algorithm

### Skim

The skim is currently used by skim, a fuzzy finder.

Skim V2:

- Just like fzf v2, the algorithm is based on Smith-Waterman algorithm which is normally used in DNA sequence alignment
- Also checkout https://www.cs.cmu.edu/~ckingsf/bioinfo-lectures/gaps.pdf for more details
- The time complexity is

where`O``(`mn`)`

are the length of the pattern and input line.`m``,`n - Space complexity is

for`O``(`mn`)`

and`fuzzy_indices`

for`O``(`2n`)`

which will compress the table for dynamic programming.`fuzzy_match` - V2 matcher has an option to set the max element of the score matrix, if

exceeded the limit, it will fallback to a linear search.`m``*`n

### Clangd

- The algorithm is based on clangd's FuzzyMatch.cpp.
- Also checkout https://github.com/lewang/flx/issues/98 for some variants.
- The algorithm is

where`O``(`mn`)`

are the length of the pattern and input line.`m``,`n - Space complexity is

for`O``(`mn`)`

and`fuzzy_indices`

for`O``(`2n`)`

which will compress the table for dynamic programming.`fuzzy_match`

#### Dependencies

~41KB