Crates.io | set-trie |
lib.rs | set-trie |
version | 0.2.3 |
source | src |
created_at | 2021-02-11 18:03:00.917672 |
updated_at | 2021-02-16 11:09:56.2011 |
description | A trie for fast subset and superset queries |
homepage | |
repository | https://github.com/kaiserkarel/set-trie |
max_upload_size | |
id | 353878 |
size | 34,278 |
Fast subset and superset queries based on tries. If you have lookup-based queries, K -> V
, but instead of looking for
an exact match with K, you want all K
's which are a subset or superset of your query, then look no further.
use set_trie::SetTrie;
fn main() {
let mut employees = SetTrie::new();
employees.insert(&["accounting", "banking"], "Daniels");
employees.insert(&["accounting", "banking", "crime"], "Stevens");
assert_eq!(employees.subsets(&[&"accounting", &"banking", &"crime"]).collect::<Vec<_>>(), vec![&"Daniels", &"Stevens"]);
assert_eq!(employees.subsets(&[&"accounting", &"banking"]).collect::<Vec<_>>(), vec![&"Daniels"]);
assert_eq!(employees.supersets(&[&"accounting"]).collect::<Vec<_>>(), vec![&"Daniels", &"Stevens"]);
}
Although currently not implemented in the type system, due to a lack of a trait bound over sorted iterators, set tries require all queries to be sorted. Failing to sort the query or key will result in nonsensical results:
use set_trie::SetTrie;
fn main() {
let mut trie = SetTrie::new();
trie.insert(&[2, 3], "Foo");
trie.insert(&[1, 2], "Bar");
// although we'd expect this to contain &"Bar".
assert_eq!(trie.subsets(&[&2, &1]).collect::<Vec<_>>(), Vec::<&&str>::new());
}
entry
API.