From e9f6120b4ca5e52cb4bebf73ce40a41650c1e173 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 9 May 2023 21:09:44 +0100 Subject: [PATCH] Implement Eq and PartialEq --- agb-hashmap/src/lib.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/agb-hashmap/src/lib.rs b/agb-hashmap/src/lib.rs index e99f6194..73c5bf31 100644 --- a/agb-hashmap/src/lib.rs +++ b/agb-hashmap/src/lib.rs @@ -787,6 +787,28 @@ where } } +impl PartialEq for HashMap +where + K: Eq + Hash, + V: PartialEq, +{ + fn eq(&self, other: &HashMap) -> bool { + if self.len() != other.len() { + return false; + } + + self.iter() + .all(|(key, value)| other.get(key).map_or(false, |v| *value == *v)) + } +} + +impl Eq for HashMap +where + K: Eq + Hash, + V: PartialEq, +{ +} + const fn number_before_resize(capacity: usize) -> usize { capacity * 85 / 100 }