From 6e5dc322cd3fac4eea960a6f2778989ccf985f95 Mon Sep 17 00:00:00 2001 From: Thalia Archibald Date: Tue, 27 Jun 2023 03:14:24 -0600 Subject: [PATCH] Implement PartialEq and Eq for map and set types --- phf/src/map.rs | 17 +++++++++++++++++ phf/src/ordered_map.rs | 20 ++++++++++++++++++++ phf/src/ordered_set.rs | 11 +++++++++++ phf/src/set.rs | 11 +++++++++++ 4 files changed, 59 insertions(+) diff --git a/phf/src/map.rs b/phf/src/map.rs index b5c7d10a..13f649b3 100644 --- a/phf/src/map.rs +++ b/phf/src/map.rs @@ -52,6 +52,23 @@ impl Default for Map { } } +impl PartialEq for Map +where + K: PartialEq, + V: PartialEq, +{ + fn eq(&self, other: &Self) -> bool { + self.key == other.key && self.disps == other.disps && self.entries == other.entries + } +} + +impl Eq for Map +where + K: Eq, + V: Eq, +{ +} + impl Map { /// Create a new, empty, immutable map. #[inline] diff --git a/phf/src/ordered_map.rs b/phf/src/ordered_map.rs index 0d5bdad1..bf6473ca 100644 --- a/phf/src/ordered_map.rs +++ b/phf/src/ordered_map.rs @@ -49,6 +49,26 @@ where } } +impl PartialEq for OrderedMap +where + K: PartialEq, + V: PartialEq, +{ + fn eq(&self, other: &Self) -> bool { + self.key == other.key + && self.disps == other.disps + && self.idxs == other.idxs + && self.entries == other.entries + } +} + +impl Eq for OrderedMap +where + K: Eq, + V: Eq, +{ +} + impl OrderedMap { /// Returns the number of entries in the `OrderedMap`. #[inline] diff --git a/phf/src/ordered_set.rs b/phf/src/ordered_set.rs index e85d4571..11e4f749 100644 --- a/phf/src/ordered_set.rs +++ b/phf/src/ordered_set.rs @@ -29,6 +29,17 @@ where } } +impl PartialEq for OrderedSet +where + T: PartialEq, +{ + fn eq(&self, other: &Self) -> bool { + self.map == other.map + } +} + +impl Eq for OrderedSet where T: Eq {} + impl OrderedSet { /// Returns the number of elements in the `OrderedSet`. #[inline] diff --git a/phf/src/set.rs b/phf/src/set.rs index d9fdd5bb..dbba3923 100644 --- a/phf/src/set.rs +++ b/phf/src/set.rs @@ -28,6 +28,17 @@ where } } +impl PartialEq for Set +where + T: PartialEq, +{ + fn eq(&self, other: &Self) -> bool { + self.map == other.map + } +} + +impl Eq for Set where T: Eq {} + impl Set { /// Returns the number of elements in the `Set`. #[inline]