[][src]Struct rb_tree::RBMap

pub struct RBMap<K: PartialOrd, V> { /* fields omitted */ }

A map implemented using a red black tree to store key-value pairs.

Implementations

impl<K: PartialOrd, V> RBMap<K, V>[src]

pub fn new() -> RBMap<K, V>[src]

Creates and returns a new, empty RBMap

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
map.insert("Hello", "World");
assert_eq!(map.remove(&"Hello").unwrap(), "World");

pub fn clear(&mut self)[src]

Clears all entries from the RBMap

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
map.insert("Hello", "world");
map.insert("Foo", "bar");
assert_eq!(map.len(), 2);
map.clear();
assert_eq!(map.len(), 0);
assert!(map.remove(&"Hello").is_none());

pub fn contains_key(&self, key: &K) -> bool[src]

Returns true if the map contains an entry for key, false otherwise.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
assert!(!map.contains_key(&"Hello"));
map.insert("Hello", "world");
assert!(map.contains_key(&"Hello"));

pub fn drain(&mut self) -> Drain<K, V>

Notable traits for Drain<K, V>

impl<K: PartialOrd, V> Iterator for Drain<K, V> type Item = (K, V);
[src]

Clears the map and returns an iterator over all key-value pairs that were contained in the order of their keys' PartialOrd order.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
map.insert("Hello", "world");
map.insert("Foo", "bar");
let mut drain = map.drain();
assert_eq!(drain.next().unwrap(), ("Foo", "bar"));
assert_eq!(drain.next().unwrap(), ("Hello", "world"));
assert!(drain.next().is_none());

pub fn get(&self, key: &K) -> Option<&V>[src]

Returns an option containing a reference to the value associated with this key, or none if this key does not have an associated value.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
assert!(map.get(&"Hello").is_none());
map.insert("Hello", "world");
assert_eq!(map.get(&"Hello").unwrap(), &"world");

pub fn get_pair(&self, key: &K) -> Option<(&K, &V)>[src]

Returns an option containing a reference to the key-value pair associated with this key, or none if this key does not have an associated value.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
assert!(map.get(&"Hello").is_none());
map.insert("Hello", "world");
assert_eq!(map.get_pair(&"Hello").unwrap(), (&"Hello", &"world"));

pub fn get_pair_mut(&mut self, key: &K) -> Option<(&K, &mut V)>[src]

Returns an option containing a reference to the key-value pair associated with this key of which the value is mutable. Returns none if this key does not have an associated value.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
assert!(map.get(&"Hello").is_none());
map.insert("Hello", "world");
assert_eq!(map.get_pair(&"Hello").unwrap(), (&"Hello", &"world"));

pub fn get_mut(&mut self, key: &K) -> Option<&mut V>[src]

Returns an option containing a mutable reference to the value associated with this key, or none if this key does not have an associated value.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
assert!(map.get(&"Hello").is_none());
map.insert("Hello", "world");
*map.get_mut(&"Hello").unwrap() = "world!";
assert_eq!(map.get(&"Hello").unwrap(), &"world!");

pub fn insert(&mut self, key: K, val: V) -> Option<(K, V)>[src]

Inserts a value to associate with the given key into the map, returning the previously-stored key-value pair if one existed, None otherwise.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
map.insert("Hello", "world");
map.insert("Foo", "bar");
assert_eq!(map.len(), 2);

pub fn is_empty(&self) -> bool[src]

Returns true if there are no key-value pairs stored in this RBMap, false otherwise.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
assert!(map.is_empty());
map.insert(1, 2);
assert!(!map.is_empty());

pub fn len(&self) -> usize[src]

Returns the number of key-value pairs stored in this RBMap.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
assert_eq!(map.len(), 0);
map.insert(1, 1);
assert_eq!(map.len(), 1);
map.insert(2, 4);
assert_eq!(map.len(), 2);
map.remove(&2);
assert_eq!(map.len(), 1);

pub fn remove(&mut self, key: &K) -> Option<V>[src]

Removes the key-value pair associated with key, if one exists, and returns the associated value, or None if the pair did not exist.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
assert!(map.remove(&2).is_none());
map.insert(2, 4);
assert_eq!(map.remove(&2).unwrap(), 4);

pub fn remove_entry(&mut self, key: &K) -> Option<(K, V)>[src]

Removes the key-value pair associated with key, if one exists, and returns it, or None if the pair did not exist.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
assert!(map.remove_entry(&2).is_none());
map.insert(2, 4);
assert_eq!(map.remove_entry(&2).unwrap(), (2, 4));

pub fn retain<F: FnMut(&K, &mut V) -> bool>(&mut self, logic: F)[src]

Removes all key-value pairs that do not return true for the provided method.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
map.insert(1, 1);
map.insert(2, 4);
map.insert(3, 9);
map.retain(|_, v| *v % 2 == 0);
 
let mut pairs = map.drain();
assert_eq!(pairs.next().unwrap(), (2, 4));
assert_eq!(pairs.next(), None);

pub fn iter(&self) -> Iter<'_, K, V>

Notable traits for Iter<'a, K, V>

impl<'a, K: PartialOrd, V> Iterator for Iter<'a, K, V> type Item = (&'a K, &'a V);
[src]

An iterator that visits all key-value pairs in their key's partialord order.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
map.insert(1, 1);
map.insert(2, 4);
map.insert(3, 9);
 
let mut pairs = map.iter();
assert_eq!(pairs.next().unwrap(), (&1, &1));
assert_eq!(pairs.next().unwrap(), (&2, &4));
assert_eq!(pairs.next().unwrap(), (&3, &9));
assert_eq!(pairs.next(), None);

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

Notable traits for IterMut<'a, K, V>

impl<'a, K: PartialOrd, V> Iterator for IterMut<'a, K, V> type Item = (&'a K, &'a mut V);
[src]

An iterator that visits all key-value pairs in their key's partialord order and presents the value only as mutable.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
map.insert(1, 1);
map.insert(2, 4);
map.insert(3, 9);
 
map.iter_mut().for_each(|(_, v)| *v *= 2);
 
let mut pairs = map.iter();
assert_eq!(pairs.next().unwrap(), (&1, &2));
assert_eq!(pairs.next().unwrap(), (&2, &8));
assert_eq!(pairs.next().unwrap(), (&3, &18));
assert_eq!(pairs.next(), None);

pub fn values(&self) -> Values<'_, K, V>

Notable traits for Values<'a, K, V>

impl<'a, K: PartialOrd, V> Iterator for Values<'a, K, V> type Item = &'a V;
[src]

An iterator that visits all values in their key's partialord order.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
map.insert(1, 1);
map.insert(2, 4);
map.insert(3, 9);
 
let mut vals = map.values();
assert_eq!(*vals.next().unwrap(), 1);
assert_eq!(*vals.next().unwrap(), 4);
assert_eq!(*vals.next().unwrap(), 9);
assert_eq!(vals.next(), None);

pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>

Notable traits for ValuesMut<'a, K, V>

impl<'a, K: PartialOrd, V> Iterator for ValuesMut<'a, K, V> type Item = &'a mut V;
[src]

An iterator that visits all values in their key's partialord order and presents them as mutable.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
map.insert(1, 1);
map.insert(2, 4);
map.insert(3, 9);
 
map.values_mut().for_each(|v| *v *= 2);
 
let mut vals = map.values();
assert_eq!(*vals.next().unwrap(), 2);
assert_eq!(*vals.next().unwrap(), 8);
assert_eq!(*vals.next().unwrap(), 18);
assert_eq!(vals.next(), None);

pub fn keys(&self) -> Keys<'_, K, V>

Notable traits for Keys<'a, K, V>

impl<'a, K: PartialOrd, V> Iterator for Keys<'a, K, V> type Item = &'a K;
[src]

An iterator that visits all keys in their partialord order.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
map.insert(1, 1);
map.insert(2, 4);
map.insert(3, 9);
 
let mut keys = map.keys();
assert_eq!(*keys.next().unwrap(), 1);
assert_eq!(*keys.next().unwrap(), 2);
assert_eq!(*keys.next().unwrap(), 3);
assert_eq!(keys.next(), None);

pub fn entry(&mut self, key: K) -> Entry<'_, K, V>[src]

Provides an interface for ensuring values are allocated to the given key.

Example:

use rb_tree::RBMap;
 
let mut map = RBMap::new();
 
let val = map.entry(1).or_insert(2);
*val = 3;
assert_eq!(*map.get(&1).unwrap(), 3);

Trait Implementations

impl<K: PartialOrd, V> FromIterator<(K, V)> for RBMap<K, V>[src]

impl<K: PartialOrd, V> IntoIterator for RBMap<K, V>[src]

type Item = (K, V)

The type of the elements being iterated over.

type IntoIter = IntoIter<K, V>

Which kind of iterator are we turning this into?

Auto Trait Implementations

impl<K, V> RefUnwindSafe for RBMap<K, V> where
    K: RefUnwindSafe,
    V: RefUnwindSafe
[src]

impl<K, V> Send for RBMap<K, V> where
    K: Send,
    V: Send
[src]

impl<K, V> Sync for RBMap<K, V> where
    K: Sync,
    V: Sync
[src]

impl<K, V> Unpin for RBMap<K, V> where
    K: Unpin,
    V: Unpin
[src]

impl<K, V> UnwindSafe for RBMap<K, V> where
    K: UnwindSafe,
    V: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.