[−][src]Struct rb_tree::RBMap
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>ⓘ
[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>ⓘ
[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>ⓘ
[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>ⓘ
[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>ⓘ
[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>ⓘ
[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]
pub fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self
[src]
impl<K: PartialOrd, V> IntoIterator for RBMap<K, V>
[src]
Auto Trait Implementations
impl<K, V> RefUnwindSafe for RBMap<K, V> where
K: RefUnwindSafe,
V: RefUnwindSafe,
[src]
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for RBMap<K, V> where
K: Send,
V: Send,
[src]
K: Send,
V: Send,
impl<K, V> Sync for RBMap<K, V> where
K: Sync,
V: Sync,
[src]
K: Sync,
V: Sync,
impl<K, V> Unpin for RBMap<K, V> where
K: Unpin,
V: Unpin,
[src]
K: Unpin,
V: Unpin,
impl<K, V> UnwindSafe for RBMap<K, V> where
K: UnwindSafe,
V: UnwindSafe,
[src]
K: UnwindSafe,
V: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,