4 releases
0.1.3 | Jul 21, 2023 |
---|---|
0.1.2 | Jun 28, 2023 |
0.1.1 | Jun 26, 2023 |
0.1.0 | Jun 26, 2023 |
#2103 in Data structures
34 downloads per month
36KB
795 lines
Fast Trie Tree
- no use
Rc
|RefCell
... - Structures such as
Rc
andRefCell
are not used, so this will be slightly faster thanTrieTree
implementations that use those structures - Use
Iterator<T: Hash + Eq>
to generalize, not only for a data type such aschar
,u8
Examples
# use fast_trie_tree::TrieTree;
let mut ctree: TrieTree<char> = TrieTree::new();
assert!(ctree.insert("abc".chars()));
assert_eq!(format!("{:#?}", ctree), concat!(
"TrieTree {\n",
" count: 1,\n",
" root: (/): {\n",
" ('a'): {\n",
" ('b'): {\n",
" ['c']: {}\n",
" }\n",
" }\n",
" },\n",
"}"
));
assert_eq!(ctree.query_iter("a".chars())
.unwrap().collect::<Vec<_>>(), [[&'b', &'c']]);
assert!(ctree.insert("ace".chars()));
assert!(ctree.query("ace".chars()));
assert!(ctree.query("abc".chars()));
assert!(! ctree.query("ab".chars()));
let byte_tree = TrieTree::from_iter(
[
[0u8, 2, 3, 8],
[4, 5, 7, 9],
[4, 2, 6, 1],
]);
assert_eq!(byte_tree.count(), 3);
assert!(byte_tree.query([0, 2, 3, 8]));
assert!(byte_tree.query([4, 5, 7, 9]));
assert!(byte_tree.query([4, 2, 6, 1]));
let mut res = byte_tree.query_iter([4]).unwrap().collect::<Vec<_>>();
res.sort();
assert_eq!(res, [[&2, &6, &1], [&5, &7, &9]]);
assert_eq!(byte_tree.count(), 3);