Struct hadean_std::hashmap::HashMap [] [src]

pub struct HashMap<K, V, S = RandomState> where K: ProcessSendable, V: ProcessSendable {
    // some fields omitted
}

A scalable distributed hash map datastructure. HashMap<K,V,S> maps keys of type K to value of type V.

It enables computation to be performed in parallel across many (key,value) pairs at the same time.

Hashing works as in std::collections::HashMap.

Here's an example showing addition and retreival of data to and from a HashMap:

extern crate hadean_std; fn main() { use hadean_std::hashmap::HashMap; let mut hash_map: HashMap<String,String> = HashMap::new(); hash_map.insert(String::from("abc"),String::from("123")); hash_map.insert(String::from("def"),String::from("456")); println!("{}", hash_map.get(&String::from("abc")).unwrap()); println!("{}", hash_map.get(&String::from("def")).unwrap()); println!("{:?}", hash_map.get(&String::from("ghi"))); }
use hadean_std::hashmap::HashMap;

let mut hash_map: HashMap<String,String> = HashMap::new();
hash_map.insert(String::from("abc"),String::from("123"));
hash_map.insert(String::from("def"),String::from("456"));
println!("{}", hash_map.get(&String::from("abc")).unwrap());
println!("{}", hash_map.get(&String::from("def")).unwrap());
println!("{:?}", hash_map.get(&String::from("ghi")));

Methods

impl<K: Hash + Eq, V> HashMap<K, V, RandomState> where K: ProcessSendable, V: ProcessSendable
[src]

fn new() -> HashMap<K, V, RandomState>

Constructs a new, empty HashMap.

impl<K, V, S> HashMap<K, V, S> where K: Hash + Eq + ProcessSendable, S: BuildHasher, V: ProcessSendable
[src]

fn insert(&mut self, k: K, v: V) -> Option<V>

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. The key is not updated, though; this matters for types that can be == without being identical. See the module-level documentation for more.

Examples

extern crate hadean_std; fn main() { use hadean_std::hashmap::HashMap; let mut map = HashMap::new(); assert_eq!(map.insert(37, "a"), None); assert_eq!(map.is_empty(), false); map.insert(37, "b"); assert_eq!(map.insert(37, "c"), Some("b")); assert_eq!(map[&37], "c"); }
use hadean_std::hashmap::HashMap;

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

map.insert(37, "b");
assert_eq!(map.insert(37, "c"), Some("b"));
assert_eq!(map[&37], "c");

fn get<Q: ?Sized>(&mut self, k: &Q) -> Option<V> where K: Borrow<Q>, Q: Hash + Eq

Returns a reference to the value corresponding to the key.

The key may be any borrowed form of the map's key type, but Hash and Eq on the borrowed form must match those for the key type.

Examples

extern crate hadean_std; fn main() { use hadean_std::hashmap::HashMap; let mut map = HashMap::new(); map.insert(1, "a"); assert_eq!(map.get(&1), Some(&"a")); assert_eq!(map.get(&2), None); }
use hadean_std::hashmap::HashMap;

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