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]

[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);

[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());

[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"));

[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);

[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));

[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));

[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);

[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);

[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());

[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<_>>());

[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));

[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<_>>());

[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<_>>());

[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]

[src]

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

impl<V: Clone> Clone for PatriciaMap<V>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<V: Debug> Debug for PatriciaMap<V>
[src]

[src]

Formats the value using the given formatter.

impl<V> IntoIterator for PatriciaMap<V>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl<K, V> FromIterator<(K, V)> for PatriciaMap<V> where
    K: AsRef<[u8]>, 
[src]

[src]

Creates a value from an iterator. Read more

impl<K, V> Extend<(K, V)> for PatriciaMap<V> where
    K: AsRef<[u8]>, 
[src]

[src]

Extends a collection with the contents of an iterator. Read more

impl<V> From<Node<V>> for PatriciaMap<V>
[src]

[src]

Performs the conversion.

impl<V> AsRef<Node<V>> for PatriciaMap<V>
[src]

[src]

Performs the conversion.