Skip to content

Commit

Permalink
Merge pull request #290 from thaliaarchi/eq-trait
Browse files Browse the repository at this point in the history
Implement PartialEq and Eq for map and set types (closes #246)
  • Loading branch information
JohnTitor committed Oct 29, 2023
2 parents 323366d + 6e5dc32 commit f89fca4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
17 changes: 17 additions & 0 deletions phf/src/map.rs
Expand Up @@ -52,6 +52,23 @@ impl<K, V> Default for Map<K, V> {
}
}

impl<K, V> PartialEq for Map<K, V>
where
K: PartialEq,
V: PartialEq,
{
fn eq(&self, other: &Self) -> bool {
self.key == other.key && self.disps == other.disps && self.entries == other.entries
}
}

impl<K, V> Eq for Map<K, V>
where
K: Eq,
V: Eq,
{
}

impl<K, V> Map<K, V> {
/// Create a new, empty, immutable map.
#[inline]
Expand Down
20 changes: 20 additions & 0 deletions phf/src/ordered_map.rs
Expand Up @@ -49,6 +49,26 @@ where
}
}

impl<K, V> PartialEq for OrderedMap<K, V>
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<K, V> Eq for OrderedMap<K, V>
where
K: Eq,
V: Eq,
{
}

impl<K, V> OrderedMap<K, V> {
/// Returns the number of entries in the `OrderedMap`.
#[inline]
Expand Down
11 changes: 11 additions & 0 deletions phf/src/ordered_set.rs
Expand Up @@ -29,6 +29,17 @@ where
}
}

impl<T> PartialEq for OrderedSet<T>
where
T: PartialEq,
{
fn eq(&self, other: &Self) -> bool {
self.map == other.map
}
}

impl<T> Eq for OrderedSet<T> where T: Eq {}

impl<T> OrderedSet<T> {
/// Returns the number of elements in the `OrderedSet`.
#[inline]
Expand Down
11 changes: 11 additions & 0 deletions phf/src/set.rs
Expand Up @@ -28,6 +28,17 @@ where
}
}

impl<T> PartialEq for Set<T>
where
T: PartialEq,
{
fn eq(&self, other: &Self) -> bool {
self.map == other.map
}
}

impl<T> Eq for Set<T> where T: Eq {}

impl<T> Set<T> {
/// Returns the number of elements in the `Set`.
#[inline]
Expand Down

0 comments on commit f89fca4

Please sign in to comment.