📐 norm
norm is a collection of different distance metrics on stings. This problem is sometimes referred to as "string similarity search", or more colloquially "fuzzy matching".
Available metrics
FzfV1
: port of the algorithm used by fzf when launching with--algo=v1
;FzfV2
: port of the algorithm used by fzf when launching without any extra flags or with--algo=v2
;
Performance
Performance is a top priority for this crate. Our goal is to have the fastest implementation of every metric algorithm we provide, across all languages. Here you can find a number of benchmarks comparing norm's metrics to each other, as well as to other popular libraries.
Example usage
use Range;
use ;
use Metric;
let mut fzf = new;
let mut parser = new;
let query = parser.parse;
let cities = ;
let mut results = cities
.iter
.copied
.filter_map
.;
// We sort the results by distance in ascending order, so that the best match
// will be at the front of the vector.
results.sort_by_key;
assert_eq!;
assert_eq!;
assert_eq!;
// We can also find out which sub-strings of each candidate matched the query.
let mut ranges: = Vec new;
let _ = fzf.distance_and_ranges;
assert_eq!;
assert_eq!; // "A" in "Adelaide"
assert_eq!; // "a" in "Adelaide"
ranges.clear;
let _ = fzf.distance_and_ranges;
assert_eq!;
assert_eq!; // The first "aa" in "Ulaanbaatar"
A note on the crate's naming scheme
norm's package.name
is norms
, while its lib.name
is norm
. This is
because the package name has to be unique to be published to crates.io, but
unfortunately norm
is already taken by a crate squatter.
What this means is that you should import norm as norms
in your Cargo.toml
,
and use
it as norm
in your source code.
For example:
# Cargo.toml
[]
= { = "0.1", = ["fzf-v2"] }
// main.rs
use FzfV2;