Crates.io | prefix_dictionary |
lib.rs | prefix_dictionary |
version | 0.0.2 |
source | src |
created_at | 2024-05-30 13:49:06.975086 |
updated_at | 2024-05-30 13:53:34.420781 |
description | Data structure similar to a dictionary, but enabling search for prefixes |
homepage | https://github.com/JeWaVe/head-dictionary |
repository | https://github.com/JeWaVe/head-dictionary |
max_upload_size | |
id | 1256882 |
size | 8,192 |
A PrefixDictionary is like a dictionary, but enabling the capacity to search by prefix. It's underlying structure is a n-ary tree.
It's generic (template) on data, but most common use is with characters.
a = PrefixDictionary("dictionary", "lapin", "lapins", "lapine")
In the examples above, only the first t
of the word "tutu" will be read as we know (from the structure of dictionary), that no words inserted starts with the letter t
.
pub fn test_simple_1() {
let mut dict = PrefixDictionary::new();
dict.feed(&["dictionary", "lapin", "lapins", "lapine"]);
assert_eq!(4, dict.len());
let mut result = dict.contains("dict");
assert!(result.is_some());
assert_eq!(result.unwrap(), SearchResult::AS_PREFIX);
result = dict.contains("lapin");
assert!(result.is_some());
assert_eq!(result.unwrap(), SearchResult::AS_PREFIX | SearchResult::AS_WORD);
result = dict.contains("dictionary");
assert!(result.is_some());
assert_eq!(result.unwrap(), SearchResult::AS_WORD);
result = dict.contains("tutu");
assert!(result.is_none());
}