Crates.io | basic_trie |
lib.rs | basic_trie |
version | 2.0.0 |
source | src |
created_at | 2023-07-22 23:58:58.299866 |
updated_at | 2024-04-09 01:51:21.370291 |
description | A simple Trie implementation in Rust |
homepage | |
repository | https://github.com/lukascobbler/basic_trie |
max_upload_size | |
id | 923472 |
size | 105,639 |
The trie data structure is used for quick access to words and data that should (could) be associated with them.
Basic Trie is implemented as a tree where each node holds a single character that could point at any other character thus allowing insertion of arbitrary words.
Regular tries are often used for word lookups and prefix matching, and data tries are often used for finding all data that is connected to some prefix.
For example, when inserting a whole book in the trie, you could insert every word with the corresponding page number it's on. Later when searching for the word, you could get all the pages the word is on with no added performance cost.
is_empty
, len
, clear
==
+
or +=
unicode-segmentation
crate (enabled by default)serde
crateunicode-segmentation
(enabled by default)serde
(only with 'serde' feature flag)fxhash
thin-vec
arrayvec
The software is licensed under the MIT license.
use basic_trie::Trie;
let mut trie = Trie::new();
trie.insert("eat");
trie.insert("eating");
trie.insert("wizard");
let mut found_longest_words = trie.get_longest();
found_longest_words.sort();
assert!(trie.contains("wizard"));
assert_eq!(vec![String::from("eating"), String::from("wizard")], found_longest_words);
assert_eq!(vec![String::from("eat")], trie.get_shortest());
assert_eq!(3, trie.len());
use basic_trie::DataTrie;
let mut data_trie = DataTrie::<u32>::new();
data_trie.insert("apple", 1);
data_trie.insert("apple", 2);
data_trie.insert_no_data("banana");
data_trie.insert("avocado", 15);
let mut found_data = data_trie.get_data("apple", false).unwrap();
found_data.sort();
assert_eq!(vec![&1, &2], found_data);
let mut found_data = data_trie.get_data("a", true).unwrap();
found_data.sort();
assert_eq!(vec![&1, &2, &15], found_data);
assert_eq!(vec![15], data_trie.remove("avocado").unwrap());
==
, +
and +=
.FxHashMap
dependency for boosted performance.serde
crate and the 'serde' feature.number_of_words()
. Removing lifetime requirements
for word insertion for much better flexibility at the same logical memory cost.insert_no_data()
for DataTrie
. Bugfixes.DataTrie
and DatalessTrie
. Optimizing
performance for DatalessTrie
. Incompatible with older versions.Trie
with data and base features.