Crate gtrie [−] [src]
Trie
Trie is the library that implements the trie.
Trie is a generic data structure, written Trie<T, U>
where T
is node key type and U
is a
value type.
Motivation
Trie may be faster than other data structures in some cases.
For example, Trie
may be used as a replacement for HashMap
in case of a dictionary where
the number of words in dictionary is significantly less than number of different words in the
input.
Usage
use gtrie::Trie; let mut t = Trie::new(); t.insert("this".chars(), 1); t.insert("trie".chars(), 2); t.insert("contains".chars(), 3); t.insert("a".chars(), 4); t.insert("number".chars(), 5); t.insert("of".chars(), 6); t.insert("words".chars(), 7); assert_eq!(t.contains("number".chars()), true); assert_eq!(t.contains("not_existing_key".chars()), false); assert_eq!(t.get_value("words".chars()), Some(7)); assert_eq!(t.get_value("none".chars()), None);
Structs
Trie |
Prefix tree object |