From 2c284f4c539efde143beb8dda5d0ad66ae056630 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 18 Nov 2023 21:57:00 -0800 Subject: [PATCH 1/3] feat: implement PartialEq for FrozenBTreeMap --- src/map.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/map.rs b/src/map.rs index befa3e6..f1115d5 100644 --- a/src/map.rs +++ b/src/map.rs @@ -283,6 +283,19 @@ impl Clone for FrozenMap { } } +impl PartialEq for FrozenMap { + 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(); + 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 { @@ -522,7 +535,7 @@ impl Clone for FrozenBTreeMap { } } -impl PartialEq for FrozenMap { +impl PartialEq for FrozenBTreeMap { fn eq(&self, other: &Self) -> bool { assert!(!self.in_use.get()); assert!(!other.in_use.get()); From 0301948b125370fc6b130354c996215248e67f7c Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Sat, 18 Nov 2023 22:00:49 -0800 Subject: [PATCH 2/3] fix: de-reference the frozen maps before comparison --- src/index_map.rs | 2 +- src/index_set.rs | 2 +- src/map.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/index_map.rs b/src/index_map.rs index 4a23352..e5ccb69 100644 --- a/src/index_map.rs +++ b/src/index_map.rs @@ -308,7 +308,7 @@ impl PartialEq for FrozenIndexMap { 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 diff --git a/src/index_set.rs b/src/index_set.rs index 2391327..152ef5e 100644 --- a/src/index_set.rs +++ b/src/index_set.rs @@ -269,7 +269,7 @@ impl PartialEq for FrozenIndexSet { 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 diff --git a/src/map.rs b/src/map.rs index f1115d5..2143e61 100644 --- a/src/map.rs +++ b/src/map.rs @@ -289,7 +289,7 @@ impl PartialEq for FrozenMap { 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 @@ -541,7 +541,7 @@ impl PartialEq for FrozenBTreeMap Date: Sat, 18 Nov 2023 22:01:49 -0800 Subject: [PATCH 3/3] fix: fix PartialEq for FrozenVec --- src/vec.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vec.rs b/src/vec.rs index 691bee4..ccd71d0 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -283,12 +283,12 @@ impl<'a, T: StableDeref> IntoIterator for &'a FrozenVec { } } -impl PartialEq for FrozenVec +impl PartialEq for FrozenVec 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() } } }