[−][src]Enum halfbrown::HashMap
Variants
Map(HashBrown<K, V>)
Vec(VecMap<K, V>)
None
Methods
impl<K, V> HashMap<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
pub fn new() -> Self
[src]
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 halfbrown::HashMap; let mut map: HashMap<&str, i32> = HashMap::new();
pub fn with_capacity(capacity: usize) -> Self
[src]
Creates an empty HashMap
with the specified capacity.
The hash map will be able to hold at least capacity
elements without
reallocating. If capacity
is 0, the hash map will not allocate.
Examples
use halfbrown::HashMap; let mut map: HashMap<&str, i32> = HashMap::with_capacity(10);
pub fn vec_with_capacity(capacity: usize) -> Self
[src]
Same as with capacity with the difference that it, despite of the
requested size always returns a vector. This allows quicker generation
when used in combination with insert_nocheck
.
Examples
use halfbrown::HashMap; let mut map: HashMap<&str, i32> = HashMap::vec_with_capacity(128); assert!(map.is_vec());
impl<K, V> HashMap<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
pub fn capacity(&self) -> usize
[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 halfbrown::HashMap; let map: HashMap<i32, i32> = HashMap::with_capacity(100); assert!(map.capacity() >= 100);
ⓘImportant traits for Keys<'a, K, V>pub fn keys(&self) -> Keys<K, V>
[src]
An iterator visiting all keys in arbitrary order.
The iterator element type is &'a K
.
Examples
use halfbrown::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>
[src]
An iterator visiting all values in arbitrary order.
The iterator element type is &'a V
.
Examples
use halfbrown::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>
[src]
An iterator visiting all values mutably in arbitrary order.
The iterator element type is &'a mut V
.
Examples
use halfbrown::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>
[src]
An iterator visiting all key-value pairs in arbitrary order.
The iterator element type is (&'a K, &'a V)
.
Examples
use halfbrown::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>
[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 halfbrown::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 len(&self) -> usize
[src]
Returns the number of elements in the map.
Examples
use halfbrown::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
[src]
Returns true
if the map contains no elements.
Examples
use halfbrown::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>
[src]
Clears the map, returning all key-value pairs as an iterator. Keeps the allocated memory for reuse.
Examples
use halfbrown::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)
[src]
Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.
Examples
use halfbrown::HashMap; let mut a = HashMap::new(); a.insert(1, "a"); a.clear(); assert!(a.is_empty());
impl<K, V> HashMap<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
pub fn reserve(&mut self, additional: usize)
[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 halfbrown::HashMap; let mut map: HashMap<&str, i32> = HashMap::new(); map.reserve(10);
pub fn shrink_to_fit(&mut self)
[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 halfbrown::HashMap; let mut map: HashMap<i32, i32> = HashMap::with_capacity(100); map.insert(1, 2); map.insert(3, 4); assert!(map.capacity() >= 100); map.shrink_to_fit(); assert!(map.capacity() >= 2);
pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V> where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
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
use halfbrown::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: ?Sized>(&self, k: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
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 halfbrown::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: ?Sized>(&mut self, k: &Q) -> Option<&mut V> where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
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 halfbrown::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>
[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 halfbrown::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: ?Sized>(&mut self, k: &Q) -> Option<V> where
K: Borrow<Q>,
Q: Hash + Eq,
[src]
K: Borrow<Q>,
Q: Hash + Eq,
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 halfbrown::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 insert_nocheck(&mut self, k: K, v: V)
[src]
pub fn is_map(&self) -> bool
[src]
Checks if the current backend is a map, if so returns true.
pub fn is_vec(&self) -> bool
[src]
Checks if the current backend is a vector, if so returns true.
Trait Implementations
impl<K, V> Default for HashMap<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
impl<K, V> PartialEq<HashMap<K, V>> for HashMap<K, V> where
K: Eq + Hash,
V: PartialEq,
[src]
K: Eq + Hash,
V: PartialEq,
fn eq(&self, other: &Self) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<K: Clone, V: Clone> Clone for HashMap<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
fn clone(&self) -> HashMap<K, V>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<K, V> IntoIterator for HashMap<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
type Item = (K, V)
The type of the elements being iterated over.
type IntoIter = IntoIter<K, V>
Which kind of iterator are we turning this into?
ⓘImportant traits for IntoIter<K, V>fn into_iter(self) -> IntoIter<K, V>
[src]
impl<'a, K, V> IntoIterator for &'a HashMap<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
type Item = (&'a K, &'a V)
The type of the elements being iterated over.
type IntoIter = Iter<'a, K, V>
Which kind of iterator are we turning this into?
ⓘImportant traits for Iter<'a, K, V>fn into_iter(self) -> Iter<'a, K, V>
[src]
impl<K: Debug, V: Debug> Debug for HashMap<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
impl<K, Q: ?Sized, V, '_> Index<&'_ Q> for HashMap<K, V> where
K: Eq + Hash + Borrow<Q>,
Q: Eq + Hash,
[src]
K: Eq + Hash + Borrow<Q>,
Q: Eq + Hash,
impl<K, V> FromIterator<(K, V)> for HashMap<K, V> where
K: Eq + Hash,
[src]
K: Eq + Hash,
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self
[src]
Auto Trait Implementations
impl<K, V> Send for HashMap<K, V> where
K: Send,
V: Send,
K: Send,
V: Send,
impl<K, V> Sync for HashMap<K, V> where
K: Sync,
V: Sync,
K: Sync,
V: Sync,
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> From for T
[src]
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,