Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for PartialEq for frozen map and vec #72

Merged
merged 3 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl<T: Hash + Eq, S: PartialEq> PartialEq for FrozenIndexMap<T, S> {
assert!(!other.in_use.get());
self.in_use.set(true);
other.in_use.set(true);
let ret = unsafe { *self.map.get() == *other.map.get() };
let ret = unsafe { self.map.get().as_ref() == other.map.get().as_ref() };
self.in_use.set(false);
other.in_use.set(false);
ret
Expand Down
2 changes: 1 addition & 1 deletion src/index_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl<T: Hash + Eq, S: BuildHasher> PartialEq for FrozenIndexSet<T, S> {
assert!(!other.in_use.get());
self.in_use.set(true);
other.in_use.set(true);
let ret = unsafe { *self.set.get() == *other.set.get() };
let ret = unsafe { self.set.get().as_ref() == other.set.get().as_ref() };
self.in_use.set(false);
other.in_use.set(false);
ret
Expand Down
17 changes: 15 additions & 2 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,19 @@ impl<K: Clone, V: Clone, S: Clone> Clone for FrozenMap<K, V, S> {
}
}

impl<K: Eq + Hash, V: PartialEq + StableDeref> PartialEq for FrozenMap<K, V> {
fn eq(&self, other: &Self) -> bool {
assert!(!self.in_use.get());
assert!(!other.in_use.get());
self.in_use.set(true);
other.in_use.set(true);
let ret = unsafe { self.map.get().as_ref() == other.map.get().as_ref() };
self.in_use.set(false);
other.in_use.set(false);
ret
}
}

/// Append-only version of `std::collections::BTreeMap` where
/// insertion does not require mutable access
pub struct FrozenBTreeMap<K, V> {
Expand Down Expand Up @@ -522,13 +535,13 @@ impl<K: Clone, V: Clone> Clone for FrozenBTreeMap<K, V> {
}
}

impl<K: Eq + Hash, V: PartialEq + StableDeref> PartialEq for FrozenMap<K, V> {
impl<K: Eq + Hash, V: PartialEq + StableDeref> PartialEq for FrozenBTreeMap<K, V> {
fn eq(&self, other: &Self) -> bool {
assert!(!self.in_use.get());
assert!(!other.in_use.get());
self.in_use.set(true);
other.in_use.set(true);
let ret = self.map.get() == other.map.get();
let ret = unsafe { self.map.get().as_ref() == other.map.get().as_ref() };
self.in_use.set(false);
other.in_use.set(false);
ret
Expand Down
4 changes: 2 additions & 2 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ impl<'a, T: StableDeref> IntoIterator for &'a FrozenVec<T> {
}
}

impl<T: StableDeref> PartialEq for FrozenVec<T>
impl<T: StableDeref + PartialEq> PartialEq for FrozenVec<T>
where
T::Target: PartialEq,
{
fn eq(&self, other: &Self) -> bool {
self.vec.get() == other.vec.get()
unsafe { self.vec.get().as_ref() == other.vec.get().as_ref() }
}
}

Expand Down
Loading