Struct hashglobe::fake::HashMap
[−]
[src]
pub struct HashMap<K, V, S = RandomState>(_);
Methods
impl<K, V, S> HashMap<K, V, S> where
K: Eq + Hash,
S: BuildHasher,
[src]
K: Eq + Hash,
S: BuildHasher,
pub fn try_with_hasher(
hash_builder: S
) -> Result<HashMap<K, V, S>, FailedAllocationError>
[src]
hash_builder: S
) -> Result<HashMap<K, V, S>, FailedAllocationError>
pub fn try_with_capacity_and_hasher(
capacity: usize,
hash_builder: S
) -> Result<HashMap<K, V, S>, FailedAllocationError>
[src]
capacity: usize,
hash_builder: S
) -> Result<HashMap<K, V, S>, FailedAllocationError>
pub fn with_capacity_and_hasher(
capacity: usize,
hash_builder: S
) -> HashMap<K, V, S>
[src]
capacity: usize,
hash_builder: S
) -> HashMap<K, V, S>
pub fn try_reserve(
&mut self,
additional: usize
) -> Result<(), FailedAllocationError>
[src]
&mut self,
additional: usize
) -> Result<(), FailedAllocationError>
pub fn try_shrink_to_fit(&mut self) -> Result<(), FailedAllocationError>
[src]
pub fn try_entry(
&mut self,
key: K
) -> Result<Entry<K, V>, FailedAllocationError>
[src]
&mut self,
key: K
) -> Result<Entry<K, V>, FailedAllocationError>
pub fn try_insert(
&mut self,
k: K,
v: V
) -> Result<Option<V>, FailedAllocationError>
[src]
&mut self,
k: K,
v: V
) -> Result<Option<V>, FailedAllocationError>
Methods from Deref<Target = StdMap<K, V, S>>
ⓘImportant traits for &'a mut Ipub fn hasher(&self) -> &S
1.9.0[src]
Returns a reference to the map's BuildHasher
.
Examples
use std::collections::HashMap; use std::collections::hash_map::RandomState; let hasher = RandomState::new(); let map: HashMap<isize, isize> = HashMap::with_hasher(hasher); let hasher: &RandomState = map.hasher();
pub fn capacity(&self) -> usize
1.0.0[src]
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 std::collections::HashMap; let map: HashMap<isize, isize> = HashMap::with_capacity(100); assert!(map.capacity() >= 100);
pub fn reserve(&mut self, additional: usize)
1.0.0[src]
Reserves capacity for at least additional
more elements to be inserted
in the HashMap
. The collection may reserve more space to avoid
frequent reallocations.
Panics
Panics if the new allocation size overflows usize
.
Examples
use std::collections::HashMap; let mut map: HashMap<&str, isize> = HashMap::new(); map.reserve(10);
pub fn shrink_to_fit(&mut self)
1.0.0[src]
Shrinks the capacity of the map as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.
Examples
use std::collections::HashMap; let mut map: HashMap<isize, isize> = HashMap::with_capacity(100); map.insert(1, 2); map.insert(3, 4); assert!(map.capacity() >= 100); map.shrink_to_fit(); assert!(map.capacity() >= 2);
ⓘImportant traits for Keys<'a, K, V>pub fn keys(&self) -> Keys<K, V>
1.0.0[src]
An iterator visiting all keys in arbitrary order.
The iterator element type is &'a K
.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for key in map.keys() { println!("{}", key); }
ⓘImportant traits for Values<'a, K, V>pub fn values(&self) -> Values<K, V>
1.0.0[src]
An iterator visiting all values in arbitrary order.
The iterator element type is &'a V
.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for val in map.values() { println!("{}", val); }
ⓘImportant traits for ValuesMut<'a, K, V>pub fn values_mut(&mut self) -> ValuesMut<K, V>
1.10.0[src]
An iterator visiting all values mutably in arbitrary order.
The iterator element type is &'a mut V
.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for val in map.values_mut() { *val = *val + 10; } for val in map.values() { println!("{}", val); }
ⓘImportant traits for Iter<'a, K, V>pub fn iter(&self) -> Iter<K, V>
1.0.0[src]
An iterator visiting all key-value pairs in arbitrary order.
The iterator element type is (&'a K, &'a V)
.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for (key, val) in map.iter() { println!("key: {} val: {}", key, val); }
ⓘImportant traits for IterMut<'a, K, V>pub fn iter_mut(&mut self) -> IterMut<K, V>
1.0.0[src]
An iterator visiting all key-value pairs in arbitrary order,
with mutable references to the values.
The iterator element type is (&'a K, &'a mut V)
.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); // Update all values for (_, val) in map.iter_mut() { *val *= 2; } for (key, val) in &map { println!("key: {} val: {}", key, val); }
pub fn entry(&mut self, key: K) -> Entry<K, V>
1.0.0[src]
Gets the given key's corresponding entry in the map for in-place manipulation.
Examples
use std::collections::HashMap; let mut letters = HashMap::new(); for ch in "a short treatise on fungi".chars() { let counter = letters.entry(ch).or_insert(0); *counter += 1; } assert_eq!(letters[&'s'], 2); assert_eq!(letters[&'t'], 3); assert_eq!(letters[&'u'], 1); assert_eq!(letters.get(&'y'), None);
pub fn len(&self) -> usize
1.0.0[src]
Returns the number of elements in the map.
Examples
use std::collections::HashMap; let mut a = HashMap::new(); assert_eq!(a.len(), 0); a.insert(1, "a"); assert_eq!(a.len(), 1);
pub fn is_empty(&self) -> bool
1.0.0[src]
Returns true if the map contains no elements.
Examples
use std::collections::HashMap; let mut a = HashMap::new(); assert!(a.is_empty()); a.insert(1, "a"); assert!(!a.is_empty());
ⓘImportant traits for Drain<'a, K, V>pub fn drain(&mut self) -> Drain<K, V>
1.6.0[src]
Clears the map, returning all key-value pairs as an iterator. Keeps the allocated memory for reuse.
Examples
use std::collections::HashMap; let mut a = HashMap::new(); a.insert(1, "a"); a.insert(2, "b"); for (k, v) in a.drain().take(1) { assert!(k == 1 || k == 2); assert!(v == "a" || v == "b"); } assert!(a.is_empty());
pub fn clear(&mut self)
1.0.0[src]
Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.
Examples
use std::collections::HashMap; let mut a = HashMap::new(); a.insert(1, "a"); a.clear(); assert!(a.is_empty());
pub fn get<Q>(&self, k: &Q) -> Option<&V> where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
1.0.0[src]
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
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
use std::collections::HashMap; let mut map = HashMap::new(); map.insert(1, "a"); assert_eq!(map.get(&1), Some(&"a")); assert_eq!(map.get(&2), None);
pub fn contains_key<Q>(&self, k: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
1.0.0[src]
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Returns true if the map contains a value for the specified 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
use std::collections::HashMap; let mut map = HashMap::new(); map.insert(1, "a"); assert_eq!(map.contains_key(&1), true); assert_eq!(map.contains_key(&2), false);
pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V> where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
1.0.0[src]
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Returns a mutable 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
use std::collections::HashMap; let mut map = HashMap::new(); map.insert(1, "a"); if let Some(x) = map.get_mut(&1) { *x = "b"; } assert_eq!(map[&1], "b");
pub fn insert(&mut self, k: K, v: V) -> Option<V>
1.0.0[src]
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 std::collections::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");
pub fn remove<Q>(&mut self, k: &Q) -> Option<V> where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
1.0.0[src]
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Removes a key from the map, returning the value at the key if the key was previously in the map.
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
use std::collections::HashMap; let mut map = HashMap::new(); map.insert(1, "a"); assert_eq!(map.remove(&1), Some("a")); assert_eq!(map.remove(&1), None);
pub fn retain<F>(&mut self, f: F) where
F: FnMut(&K, &mut V) -> bool,
1.18.0[src]
F: FnMut(&K, &mut V) -> bool,
Retains only the elements specified by the predicate.
In other words, remove all pairs (k, v)
such that f(&k,&mut v)
returns false
.
Examples
use std::collections::HashMap; let mut map: HashMap<isize, isize> = (0..8).map(|x|(x, x*10)).collect(); map.retain(|&k, _| k % 2 == 0); assert_eq!(map.len(), 4);
Trait Implementations
impl<K: Clone, V: Clone, S: Clone> Clone for HashMap<K, V, S>
[src]
fn clone(&self) -> HashMap<K, V, S>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<K, V, S> Deref for HashMap<K, V, S>
[src]
type Target = StdMap<K, V, S>
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
Dereferences the value.
impl<K, V, S> DerefMut for HashMap<K, V, S>
[src]
impl<K: Hash + Eq, V, S: BuildHasher + Default> Default for HashMap<K, V, S>
[src]
impl<K, V, S> Debug for HashMap<K, V, S> where
K: Eq + Hash + Debug,
V: Debug,
S: BuildHasher,
[src]
K: Eq + Hash + Debug,
V: Debug,
S: BuildHasher,
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<K, V, S> PartialEq for HashMap<K, V, S> where
K: Eq + Hash,
V: PartialEq,
S: BuildHasher,
[src]
K: Eq + Hash,
V: PartialEq,
S: BuildHasher,
fn eq(&self, other: &HashMap<K, V, S>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<K, V, S> Eq for HashMap<K, V, S> where
K: Eq + Hash,
V: Eq,
S: BuildHasher,
[src]
K: Eq + Hash,
V: Eq,
S: BuildHasher,
impl<'a, K, V, S> IntoIterator for &'a HashMap<K, V, S> where
K: Eq + Hash,
S: BuildHasher,
[src]
K: Eq + Hash,
S: BuildHasher,
type Item = (&'a K, &'a V)
The type of the elements being iterated over.
type IntoIter = MapIter<'a, K, V>
Which kind of iterator are we turning this into?
ⓘImportant traits for Iter<'a, K, V>fn into_iter(self) -> MapIter<'a, K, V>
[src]
Creates an iterator from a value. Read more
impl<'a, K, V, S> IntoIterator for &'a mut HashMap<K, V, S> where
K: Eq + Hash,
S: BuildHasher,
[src]
K: Eq + Hash,
S: BuildHasher,