Struct gtrie::Trie[][src]

pub struct Trie<T, U> { /* fields omitted */ }

Prefix tree object

Methods

impl<T: Eq + Ord + Clone, U: Clone> Trie<T, U>
[src]

Creates a new Trie object

Example

use gtrie::Trie;

let t = Trie::<char, String>::new();

Checks that trie is empty

Example

use gtrie::Trie;

let t = Trie::<char, f64>::new();
assert_eq!(t.is_empty(), true);

Adds a new key to the trie

Example

use gtrie::Trie;

let mut t = Trie::new();
let data = "test".chars();

t.insert(data, 42);
assert_eq!(t.is_empty(), false);

Clears the trie

Example

use gtrie::Trie;

let mut t = Trie::new();
let data = "test".chars();

t.insert(data, String::from("test"));
t.clear();
assert_eq!(t.is_empty(), true);

Looks for the key in trie

Example

use gtrie::Trie;

let mut t = Trie::new();
let data = "test".chars();
let another_data = "notintest".chars();

t.insert(data.clone(), 42);

assert_eq!(t.is_empty(), false);
assert_eq!(t.contains_key(data), true);
assert_eq!(t.contains_key(another_data), false);

Gets the value from the tree by key

Example

use gtrie::Trie;

let mut t = Trie::new();
let data = "test".chars();
let another_data = "notintest".chars();

t.insert(data.clone(), 42);

assert_eq!(t.get_value(data), Some(42));
assert_eq!(t.get_value(another_data), None);

Sets the value pointed by a key

Example

use gtrie::Trie;

let mut t = Trie::new();
let data = "test".chars();
let another_data = "notintest".chars();

t.insert(data.clone(), 42);

assert_eq!(t.get_value(data.clone()), Some(42));
assert_eq!(t.set_value(data.clone(), 43), Ok(()));
assert_eq!(t.get_value(data), Some(43));
assert_eq!(t.set_value(another_data, 39), Err(()));

Auto Trait Implementations

impl<T, U> Send for Trie<T, U> where
    T: Send,
    U: Send

impl<T, U> Sync for Trie<T, U> where
    T: Sync,
    U: Sync