Struct llrb::LLRB [] [src]

pub struct LLRB<K: Ord, V> { /* fields omitted */ }

Methods

impl<K: Ord, V> LLRB<K, V>
[src]

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the tree's key type, but the ordering on the borrowed form must match the ordering on the key type.

Examples

Basic usage:

use llrb::LLRB;

let mut tree = LLRB::new();
tree.insert(1, "a");
assert_eq!(tree.get(&1), Some(&"a"));
assert_eq!(tree.get(&2), None);

Returns true if the tree contains a value for the specified key.

The key may be any borrowed form of the tree's key type, but the ordering on the borrowed form must match the ordering on the key type.

Examples

Basic usage:

use llrb::LLRB;

let mut tree = LLRB::new();
tree.insert(1, "a");
assert_eq!(tree.contains_key(&1), true);
assert_eq!(tree.contains_key(&2), false);

Returns a mutable reference to the value corresponding to the key.

The key may be any borrowed form of the tree's key type, but the ordering on the borrowed form must match the ordering on the key type.

Examples

Basic usage:

use llrb::LLRB;

let mut tree = LLRB::new();
tree.insert(1, "a");
if let Some(x) = tree.get_mut(&1) {
    *x = "b";
}
assert_eq!(tree[&1], "b");

Inserts a key-value pair into the tree.

If the tree did not have this key present, None is returned.

If the tree did have this key present, the value is updated, and the old value is returned. The key is not updated, though; this matters for types that can be == without being identical.

Examples

Basic usage:

use llrb::LLRB;

let mut tree = LLRB::new();
assert_eq!(tree.insert(37, "a"), None);
assert_eq!(tree.is_empty(), false);

tree.insert(37, "b");
assert_eq!(tree.insert(37, "c"), Some("b"));
assert_eq!(tree[&37], "c");

Removes a key from the tree, returning the value at the key if the key was previously in the tree.

The key may be any borrowed form of the tree's key type, but the ordering on the borrowed form must match the ordering on the key type.

Examples

Basic usage:

use llrb::LLRB;

let mut tree = LLRB::new();
tree.insert(1, "a");
assert_eq!(tree.remove(&1), Some("a"));
assert_eq!(tree.remove(&1), None);

Moves all elements from other into Self, leaving other empty.

Examples

use llrb::LLRB;

let mut a = LLRB::new();
a.insert(1, "a");
a.insert(2, "b");
a.insert(3, "c");

let mut b = LLRB::new();
b.insert(3, "d");
b.insert(4, "e");
b.insert(5, "f");

a.append(&mut b);

assert_eq!(a.len(), 5);
assert_eq!(b.len(), 0);

assert_eq!(a[&1], "a");
assert_eq!(a[&2], "b");
assert_eq!(a[&3], "d");
assert_eq!(a[&4], "e");
assert_eq!(a[&5], "f");

Returns the number of elements in the tree.

Examples

Basic usage:

use llrb::LLRB;

let mut a = LLRB::new();
assert_eq!(a.len(), 0);
a.insert(1, "a");
assert_eq!(a.len(), 1);

Returns true if the tree contains no elements.

Examples

Basic usage:

use llrb::LLRB;

let mut a = LLRB::new();
assert!(a.is_empty());
a.insert(1, "a");
assert!(!a.is_empty());

Trait Implementations

impl<K: Debug + Ord, V: Debug> Debug for LLRB<K, V>
[src]

Formats the value using the given formatter.

impl<K: PartialEq + Ord, V: PartialEq> PartialEq for LLRB<K, V>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<K: Eq + Ord, V: Eq> Eq for LLRB<K, V>
[src]

impl<K: Ord, V> Default for LLRB<K, V>
[src]

Returns the "default value" for a type. Read more

impl<'a, K: Ord, V> Index<&'a K> for LLRB<K, V> where
    K: Ord
[src]

The returned type after indexing

The method for the indexing (container[index]) operation