Crates.io | fuzzy_prefix_search |
lib.rs | fuzzy_prefix_search |
version | 0.3.6 |
source | src |
created_at | 2024-08-06 13:41:54.067875 |
updated_at | 2024-09-12 05:57:45.943113 |
description | Fuzzy search for prefix matches |
homepage | https://github.com/tpisto/fuzzy_prefix_search |
repository | https://github.com/tpisto/fuzzy_prefix_search |
max_upload_size | |
id | 1327307 |
size | 50,250 |
Flexible Trie implementation in Rust for fuzzy prefix string searching and auto-completion.
Documentation:
Add this to your Cargo.toml
:
[dependencies]
fuzzy_prefix_search = "0.2"
Here's a quick example of how to use the Fuzzy Prefix Search:
use fuzzy_prefix_search::Trie;
fn main() {
let mut trie = Trie::new();
// Insert words with associated data
trie.insert("apple", 1);
trie.insert("application", 2);
trie.insert("appetite", 3);
// Perform a fuzzy search
let results = trie.search_within_distance("appl", 1);
for result in results {
println!("Word: {}, Data: {:?}", result.word, result.data);
}
// Search with similarity scoring
let scored_results = trie.search_within_distance_scored("aple", 2);
for result in scored_results {
println!("Word: {}, Data: {:?}, Score: {}", result.word, result.data, result.score);
}
}
The Trie supports any data type that implements Clone
, PartialEq
, Eq
, and Hash
:
#[derive(Clone, PartialEq, Eq, Hash)]
struct CustomData {
id: u32,
value: String,
}
let mut trie = Trie::new();
trie.insert("example", CustomData { id: 1, value: "Test".to_string() });
You can remove all occurrences of a specific data value:
trie.remove_all(&2);
Caveat Emptor: we use unsafe in deletes for 2x read performance compared to Rc/RefCell approach.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT or Apache 2.0 License - see the LICENSE files for details.