mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 08:41:34 +11:00
Add default implementation
This commit is contained in:
parent
6ff4cbe4f1
commit
5edd46e085
|
@ -171,6 +171,12 @@ impl<K, V> HashMap<K, V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<K, V> Default for HashMap<K, V> {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const fn fast_mod(len: usize, hash: HashType) -> usize {
|
const fn fast_mod(len: usize, hash: HashType) -> usize {
|
||||||
debug_assert!(len.is_power_of_two(), "Length must be a power of 2");
|
debug_assert!(len.is_power_of_two(), "Length must be a power of 2");
|
||||||
(hash as usize) & (len - 1)
|
(hash as usize) & (len - 1)
|
||||||
|
@ -235,6 +241,13 @@ where
|
||||||
.map(|location| &self.nodes.0[location].as_ref().unwrap().value)
|
.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<V> {
|
pub fn remove(&mut self, key: &K) -> Option<V> {
|
||||||
let hash = self.hash(key);
|
let hash = self.hash(key);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue