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 std::HashMap in case of a dictionary where the number of words in dictionary is significantly less than number of different words in the input and matching probability is low.

Important

Search performance is highly dependent on the data stored in Trie and may be as significantly faster than std::HashMap as significantly slower.

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_key("number".chars()), true);
assert_eq!(t.contains_key("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