Struct llrb::LLRB
[−]
[src]
pub struct LLRB<K: Ord, V> { /* fields omitted */ }
Methods
impl<K: Ord, V> LLRB<K, V>
[src]
fn new() -> LLRB<K, V>
fn get(&self, k: &K) -> Option<&V>
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);
fn contains_key(&self, k: &K) -> bool
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);
fn get_mut(&mut self, k: &K) -> Option<&mut V>
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");
fn insert(&mut self, k: K, v: V) -> Option<V>
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");
fn remove(&mut self, k: &K) -> Option<V>
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);
fn append(&mut self, other: &mut Self)
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");
fn len(&self) -> usize
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);
fn is_empty(&self) -> bool
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]
impl<K: PartialEq + Ord, V: PartialEq> PartialEq for LLRB<K, V>
[src]
fn eq(&self, __arg_0: &LLRB<K, V>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &LLRB<K, V>) -> bool
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]
impl<'a, K: Ord, V> Index<&'a K> for LLRB<K, V> where
K: Ord,
[src]
K: Ord,