Struct patricia_tree::map::PatriciaMap
[−]
[src]
pub struct PatriciaMap<V> { /* fields omitted */ }
A map based on a patricia tree.
Methods
impl<V> PatriciaMap<V>
[src]
fn new() -> Self
[src]
Makes a new empty PatriciaMap
instance.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); assert!(map.is_empty()); map.insert("foo", 10); assert_eq!(map.len(), 1); assert_eq!(map.get("foo"), Some(&10)); map.remove("foo"); assert_eq!(map.get("foo"), None);
fn clear(&mut self)
[src]
Clears this map, removing all values.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); map.insert("foo", 1); map.clear(); assert!(map.is_empty());
fn contains_key<K: AsRef<[u8]>>(&self, key: K) -> bool
[src]
Returns true
if this map contains a value for the specified key.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); map.insert("foo", 1); assert!(map.contains_key("foo")); assert!(!map.contains_key("bar"));
fn get<K: AsRef<[u8]>>(&self, key: K) -> Option<&V>
[src]
Returns a reference to the value corresponding to the key.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); map.insert("foo", 1); assert_eq!(map.get("foo"), Some(&1)); assert_eq!(map.get("bar"), None);
fn get_mut<K: AsRef<[u8]>>(&mut self, key: K) -> Option<&mut V>
[src]
Returns a mutable reference to the value corresponding to the key.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); map.insert("foo", 1); map.get_mut("foo").map(|v| *v = 2); assert_eq!(map.get("foo"), Some(&2));
fn insert<K: AsRef<[u8]>>(&mut self, key: K, value: V) -> Option<V>
[src]
Inserts a key-value pair into this map.
If the map did not have this key present, None
is returned.
If the map did have this key present, the value is updated, and the old value is returned.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); assert_eq!(map.insert("foo", 1), None); assert_eq!(map.get("foo"), Some(&1)); assert_eq!(map.insert("foo", 2), Some(1)); assert_eq!(map.get("foo"), Some(&2));
fn remove<K: AsRef<[u8]>>(&mut self, key: K) -> Option<V>
[src]
Removes a key from this map, returning the value at the key if the key was previously in it.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); map.insert("foo", 1); assert_eq!(map.remove("foo"), Some(1)); assert_eq!(map.remove("foo"), None);
fn len(&self) -> usize
[src]
Returns the number of elements in this map.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); map.insert("foo", 1); map.insert("bar", 2); assert_eq!(map.len(), 2);
fn is_empty(&self) -> bool
[src]
Returns true
if this map contains no elements.
Examples
use patricia_tree::PatriciaMap; let mut map = PatriciaMap::new(); assert!(map.is_empty()); map.insert("foo", 1); assert!(!map.is_empty()); map.clear(); assert!(map.is_empty());
fn iter(&self) -> Iter<V>
[src]
Gets an iterator over the entries of this map, sorted by key.
Examples
use patricia_tree::PatriciaMap; let map: PatriciaMap<_> = vec![("foo", 1), ("bar", 2), ("baz", 3)].into_iter().collect(); assert_eq!(vec![(Vec::from("bar"), &2), ("baz".into(), &3), ("foo".into(), &1)], map.iter().collect::<Vec<_>>());
fn iter_mut(&mut self) -> IterMut<V>
[src]
Gets a mutable iterator over the entries of this map, soretd by key.
Examples
use patricia_tree::PatriciaMap; let mut map: PatriciaMap<_> = vec![("foo", 1), ("bar", 2), ("baz", 3)].into_iter().collect(); for (_, v) in map.iter_mut() { *v += 10; } assert_eq!(map.get("bar"), Some(&12));
fn keys(&self) -> Keys<V>
[src]
Gets an iterator over the keys of this map, in sorted order.
Examples
use patricia_tree::PatriciaMap; let map: PatriciaMap<_> = vec![("foo", 1), ("bar", 2), ("baz", 3)].into_iter().collect(); assert_eq!(vec![Vec::from("bar"), "baz".into(), "foo".into()], map.keys().collect::<Vec<_>>());
fn values(&self) -> Values<V>
[src]
Gets an iterator over the values of this map, in order by key.
Examples
use patricia_tree::PatriciaMap; let map: PatriciaMap<_> = vec![("foo", 1), ("bar", 2), ("baz", 3)].into_iter().collect(); assert_eq!(vec![2, 3, 1], map.values().cloned().collect::<Vec<_>>());
fn values_mut(&mut self) -> ValuesMut<V>
[src]
Gets a mutable iterator over the values of this map, in order by key.
Examples
use patricia_tree::PatriciaMap; let mut map: PatriciaMap<_> = vec![("foo", 1), ("bar", 2), ("baz", 3)].into_iter().collect(); for v in map.values_mut() { *v += 10; } assert_eq!(vec![12, 13, 11], map.values().cloned().collect::<Vec<_>>());
Trait Implementations
impl<V: Default> Default for PatriciaMap<V>
[src]
fn default() -> PatriciaMap<V>
[src]
Returns the "default value" for a type. Read more
impl<V: Clone> Clone for PatriciaMap<V>
[src]
fn clone(&self) -> PatriciaMap<V>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<V: Debug> Debug for PatriciaMap<V>
[src]
impl<V> IntoIterator for PatriciaMap<V>
[src]
type Item = (Vec<u8>, V)
The type of the elements being iterated over.
type IntoIter = IntoIter<V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
Creates an iterator from a value. Read more
impl<K, V> FromIterator<(K, V)> for PatriciaMap<V> where
K: AsRef<[u8]>,
[src]
K: AsRef<[u8]>,
fn from_iter<I>(iter: I) -> Self where
I: IntoIterator<Item = (K, V)>,
[src]
I: IntoIterator<Item = (K, V)>,
Creates a value from an iterator. Read more
impl<K, V> Extend<(K, V)> for PatriciaMap<V> where
K: AsRef<[u8]>,
[src]
K: AsRef<[u8]>,
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = (K, V)>,
[src]
I: IntoIterator<Item = (K, V)>,
Extends a collection with the contents of an iterator. Read more