Struct ::std::collections::HashMap
Methods
Creates an empty HashMap
.
The hash map is initially created with a capacity of 0, so it will not allocate until it is first inserted into.
Examples
use HashMap;
let map = new;
Creates an empty HashMap
with at least the specified capacity.
The hash map will be able to hold at least capacity
elements without reallocating. This method is allowed to allocate for more elements than capacity
. If capacity
is 0, the hash map will not allocate.
Examples
use HashMap;
let map = with_capacity;
Returns the number of elements in the map.
Examples
use HashMap;
let a = new;
assert_eq!;
a.insert;
assert_eq!;
Returns the number of elements the map can hold without reallocating.
This number is a lower bound; the HashMap<K, V>
might be able to hold more, but is guaranteed to be able to hold at least this many.
Examples
use HashMap;
let map = with_capacity;
assert!;
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
use HashMap;
let map = new;
assert_eq!;
assert_eq!;
map.insert;
assert_eq!;
assert_eq!;
Returns the value corresponding to the [Key
].
Examples
use HashMap;
let map = new;
map.insert;
assert_eq!;
assert_eq!;
Returns true
if the map contains a value for the specified [Key
].
Examples
use HashMap;
let map = new;
map.insert;
assert_eq!;
assert_eq!;
Removes a key from the map, returning the value at the [Key
] if the key was previously in the map.
Examples
use HashMap;
let map = new;
map.insert;
assert_eq!;
assert_eq!;
Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.
Examples
use HashMap;
let a = new;
a.insert;
a.clear;
assert!;
Returns true
if the map contains no elements.
Examples
use HashMap;
let a = new;
assert!;
a.insert;
assert!;
An iterator visiting all key-value pairs in arbitrary order.
Examples
use HashMap;
let map = from;
let pairs = map.iter .;
pairs.sort;
assert_eq!;
Performance
In the current implementation, iterating over map takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
An iterator visiting all keys in arbitrary order.
Examples
use HashMap;
let map = from;
let keys = map.keys .;
keys.sort;
assert_eq!;
Performance
In the current implementation, iterating over keys takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
An iterator visiting all values in arbitrary order.
Examples
use HashMap;
let map = from;
let values = map.values .;
values.sort;
assert_eq!;
Performance
In the current implementation, iterating over values takes O(capacity) time instead of O(len) because it internally visits empty buckets too.
Extend this map from an iterator.
Examples
use HashMap;
let map = new;
map.extend;
Convert a hashmap from a value
.
The hashmap can be converted from anything that implements the [INTO_ITER
] protocol, and each item produces should be a tuple pair.
Clone the map.
Examples
use HashMap;
let a = from;
let b = a.clone;
b.insert;
assert_eq!;
assert_eq!;
Protocols
value= input
Inserts a key-value pair into the map.
If the map did have this key present, the value is updated.
Examples
use HashMap;
let map = new;
map = "a";
assert!;
map = "c";
assert_eq!;
let output = value
Returns a the value corresponding to the key.
Panics
Panics if the given value is not present in the map.
use HashMap;
let map = new;
let _ = map;
Examples
use HashMap;
let map = new;
map = "a";
assert_eq!;
println
Debug format the current map.
Examples
use HashMap;
let map = new;
map = "a";
assert_eq!;
if value == b
Perform a partial equality check over two maps.
Examples
use HashMap;
let map1 = from;
let map2 = from;
assert!;
map1 = f64NAN;
map2 = f64NAN;
assert!;
if value == b
Perform a total equality check over two maps.
Examples
use HashMap;
use eq;
let map1 = from;
let map2 = from;
assert!;
for item in value
An iterator visiting all key-value pairs in arbitrary order.
Examples
use HashMap;
let map = from;
let pairs = ;
for pair in map
pairs.sort;
assert_eq!;
Performance
In the current implementation, iterating over map takes O(capacity) time instead of O(len) because it internally visits empty buckets too.