Struct panoradix::RadixMap [] [src]

pub struct RadixMap<K: Key + ?Sized, V> { /* fields omitted */ }

A map based on a Radix tree.

TODO: section on benefits/drawbacks of using a Radix tree

Methods

impl<K: Key + ?Sized, V> RadixMap<K, V>
[src]

Makes a new empty RadixMap.

Examples

Basic usage:

use panoradix::RadixMap;

let mut map = RadixMap::new();

// entries can now be inserted into the empty map
map.insert("a", 1);

Clears the map, removing all values.

Examples

Basic usage:

use panoradix::RadixMap;

let mut m = RadixMap::new();
m.insert("a", 1);
m.clear();
assert!(m.is_empty());

Inserts a key-value pair into the 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

Basic usage:

use panoradix::RadixMap;

let mut map = RadixMap::new();
assert_eq!(map.insert("a", 37), None);
assert_eq!(map.is_empty(), false);

map.insert("a", 42);
assert_eq!(map.insert("a", 1337), Some(42));

Returns a reference to the value corresponding to the key.

Examples

Basic usage:

use panoradix::RadixMap;

let mut map = RadixMap::new();
map.insert("a", 1);
assert_eq!(map.get("a"), Some(&1));
assert_eq!(map.get("b"), None);

Returns true if the map contains no elements.

Examples

Basic usage:

use panoradix::RadixMap;

let mut a = RadixMap::new();
assert!(a.is_empty());
a.insert("a", ());
assert!(!a.is_empty());

Removes a key from the map, returning the value at the key if the key was previously in the map.

Examples

Basic usage:

use panoradix::RadixMap;

let mut map = RadixMap::new();
map.insert("a", 1);
assert_eq!(map.remove("a"), Some(1));
assert_eq!(map.remove("a"), None);

Gets an iterator over the entries of the map, sorted by key.

Examples

Basic usage:

use panoradix::RadixMap;

let mut map = RadixMap::new();
map.insert("c", 3);
map.insert("b", 2);
map.insert("a", 1);

for (key, value) in map.iter() {
    println!("{}: {}", key, value);
}

let (first_key, first_value) = map.iter().next().unwrap();
assert_eq!((first_key, *first_value), ("a".to_string(), 1));

Gets an iterator over the keys of the map (sorted).

Examples

Basic usage:

use panoradix::RadixMap;

let mut map = RadixMap::new();
map.insert("c", 3);
map.insert("b", 2);
map.insert("a", 1);

for key in map.keys() {
    println!("{}", key);
}

let first_key = map.keys().next().unwrap();
assert_eq!(first_key, "a".to_string());

Gets an iterator over the values of the map, sorted by corresponding key.

Examples

Basic usage:

use panoradix::RadixMap;

let mut map = RadixMap::new();
map.insert("c", 3);
map.insert("b", 2);
map.insert("a", 1);

for value in map.values() {
    println!("{}", value);
}

let first_value = map.values().next().unwrap();
assert_eq!(first_value, &1);

Gets an iterator over a filtered subset of the map, sorted by key.

The iterator resembles iter() since it yields key-value pairs from the map. Note that the full key will be yielded each time, not just the filtered suffix.

Examples

Basic usage:

use panoradix::RadixMap;

let mut map = RadixMap::new();
map.insert("abc", 1);
map.insert("acd", 2);
map.insert("abd", 3);
map.insert("bbb", 1);
map.insert("ccc", 1);

for (key, value) in map.find("a") {
    println!("{}: {}", key, value);
}

let (first_key, first_value) = map.find("a").next().unwrap();
assert_eq!((first_key, first_value), ("abc".to_string(), &1));

Trait Implementations

impl<K: Key + ?Sized, V> Default for RadixMap<K, V>
[src]

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

impl<K: ?Sized, V, T> FromIterator<(T, V)> for RadixMap<K, V> where
    K: Key,
    T: AsRef<K>, 
[src]

Creates a value from an iterator. Read more