Fuzzies
Fuzzies is a fast fuzzy string matching crate built on fst and levenshtein-automata
More information about this crate can be found in the crate documentation
Installation
Example
use ;
If you don't want to manage external .fst files on disk, you can construct a Dictionary directly:
// From an embedded FST binary slice:
static DICT_DATA: & = include_bytes!;
let dict = from_embedded?;
// From an iterator of strings (automatically sorted and deduplicated):
let words = vec!;
let dict = from_iterator?;
🎈 Performance
The following benchmarks were gathered using Criterion on an Intel Core i5-10300H (4 cores / 8 threads). You can re-run these on your hardware with cargo bench.
[!NOTE] Running
cargo benchon the published crate executes against a small, dynamically generated dataset. The 106,000-word benchmarks shown below were gathered independently using a local dictionary.
Setup & Initialization
| Operation | 1,000 Entries | 106,000 Entries |
|---|---|---|
Dictionary::sort |
36.87 µs | — |
Dictionary::build |
130.97 µs | — |
Dictionary::open |
2.78 µs | 6.96 µs |
Dictionary::from_embedded |
11.75 ns | 11.77 ns |
Dictionary::len / is_empty |
~0.45 ns | ~0.45 ns |
Search & Queries
| Operation | 1,000 Entries | 106,000 Entries | Scaling Factor |
|---|---|---|---|
| contains (Hit) | 34.50 ns | 63.94 ns | ~1.9x |
| contains (Miss) | 11.13 ns | 97.84 ns | ~8.8x |
| Exact Search (dist = 0) | 2.01 µs | 4.26 µs | ~2.1x |
| Fuzzy Search (dist = 1) | 8.31 µs | 64.55 µs | ~7.8x |
| Prefix Search | 5.43 µs | 125.95 µs | Result-size bound |
Range Search ('b'..='c') |
4.19 µs | 637.90 µs | Result-size bound |
| Batch (1,000 queries) | 4.08 ms (4.0 µs/q) | 14.88 ms (14.8 µs/q) | ~3.6x |
Safety
This crate uses unsafe in a single location:
- Memory-Mapped I/O (
Dictionary::open): Callsmemmap2::Mmap::map(&file)to map FST data directly from disk into memory.
License
This project is licensed under the MIT license.