Crate btreemultimap[][src]

A BTreeMultiMap implementation which is just a wrapper around std::collections::BTreeMap. See BTreeMap’s documentation for more details.

Some of the methods are just thin wrappers, some methods does change a little semantics and some methods are new (doesn’t have an equivalent in BTreeMap.)

The BTreeMultiMap is generic for the key (K) and the value (V). Internally the values are stored in a generic Vector.

Examples

use btreemultimap::BTreeMultiMap;

// create a new BTreeMultiMap. An explicit type signature can be omitted because of the
// type inference.
let mut queries = BTreeMultiMap::new();

// insert some queries.
queries.insert("urls", "http://rust-lang.org");
queries.insert("urls", "http://mozilla.org");
queries.insert("urls", "http://wikipedia.org");
queries.insert("id", "42");
queries.insert("name", "roger");

// check if there's any urls.
println!("Are there any urls in the btree multimap? {:?}.",
    if queries.contains_key("urls") {"Yes"} else {"No"} );

// get the first item in a key's vector.
assert_eq!(queries.get("urls"), Some(&"http://rust-lang.org"));

// get all the urls.
assert_eq!(queries.get_vec("urls"),
    Some(&vec!["http://rust-lang.org", "http://mozilla.org", "http://wikipedia.org"]));

// iterate over all keys and the first value in the key's vector.
for (key, value) in queries.iter() {
    println!("key: {:?}, val: {:?}", key, value);
}

// iterate over all keys and the key's vector.
for (key, values) in queries.iter() {
    println!("key: {:?}, values: {:?}", key, values);
}

// the different methods for getting value(s) from the btree multimap.
let mut map = BTreeMultiMap::new();

map.insert("key1", 42);
map.insert("key1", 1337);

assert_eq!(map["key1"], 42);
assert_eq!(map.get("key1"), Some(&42));
assert_eq!(map.get_vec("key1"), Some(&vec![42, 1337]));

Modules

serde

Serde trait implementations for MultiMap

Macros

btreemultimap

Create a BTreeMultiMap from a list of key value pairs

Structs

BTreeMultiMap
MultiIter
MultiIterMut
MultiRange
MultiRangeMut
OccupiedEntry

A view into a single occupied location in a BTreeMultiMap.

VacantEntry

A view into a single empty location in a BTreeMultiMap.

Enums

Entry

A view into a single location in a map, which may be vacant or occupied.