From 5edd46e0850ef86d3b2cc283248cf777e26dacb3 Mon Sep 17 00:00:00 2001 From: Gwilym Kuiper Date: Fri, 18 Mar 2022 00:21:55 +0000 Subject: [PATCH] Add default implementation --- agb/src/hash_map.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/agb/src/hash_map.rs b/agb/src/hash_map.rs index 104d4f77..06db6181 100644 --- a/agb/src/hash_map.rs +++ b/agb/src/hash_map.rs @@ -171,6 +171,12 @@ impl HashMap { } } +impl Default for HashMap { + fn default() -> Self { + Self::new() + } +} + const fn fast_mod(len: usize, hash: HashType) -> usize { debug_assert!(len.is_power_of_two(), "Length must be a power of 2"); (hash as usize) & (len - 1) @@ -235,6 +241,13 @@ where .map(|location| &self.nodes.0[location].as_ref().unwrap().value) } + pub fn get_mut(&mut self, key: &K) -> Option<&mut V> { + let hash = self.hash(key); + + self.get_location(key, hash) + .map(|location| &mut self.nodes.0[location].as_mut().unwrap().value) + } + pub fn remove(&mut self, key: &K) -> Option { let hash = self.hash(key);