Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into clone-except-lock…
Browse files Browse the repository at this point in the history
…-free-vec
  • Loading branch information
aminya committed Oct 23, 2023
2 parents 0a330c0 + 3750bca commit a2b1fe4
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/index_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,16 @@ impl<K: Clone, V: Clone, S: Clone> Clone for FrozenIndexMap<K, V, S> {
return self_clone;
}
}

impl<T: Hash + Eq, S: PartialEq> PartialEq for FrozenIndexMap<T, S> {
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() == *other.map.get() };
self.in_use.set(false);
other.in_use.set(false);
ret
}
}
13 changes: 13 additions & 0 deletions src/index_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,16 @@ impl<K: Clone, V: Clone> Clone for FrozenIndexSet<K, V> {
return self_clone;
}
}

impl<T: Hash + Eq, S: BuildHasher> PartialEq for FrozenIndexSet<T, S> {
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.set.get() == *other.set.get() };
self.in_use.set(false);
other.in_use.set(false);
ret
}
}
13 changes: 13 additions & 0 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,3 +521,16 @@ impl<K: Clone, V: Clone> Clone for FrozenBTreeMap<K, V> {
return self_clone;
}
}

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 = self.map.get() == other.map.get();
self.in_use.set(false);
other.in_use.set(false);
ret
}
}
25 changes: 25 additions & 0 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use stable_deref_trait::StableDeref;
use std::alloc::Layout;
use std::borrow::Borrow;
use std::cmp::Eq;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::fmt;
Expand Down Expand Up @@ -422,6 +423,14 @@ impl<K: Clone, V: Clone> Clone for FrozenMap<K, V> {
}
}

impl<K: Eq + Hash, V: PartialEq> PartialEq for FrozenMap<K, V> {
fn eq(&self, other: &Self) -> bool {
let self_ref: &HashMap<K, V> = &self.map.read().unwrap();
let other_ref: &HashMap<K, V> = &other.map.read().unwrap();
self_ref == other_ref
}
}

/// Append-only threadsafe version of `std::vec::Vec` where
/// insertion does not require mutable access
pub struct FrozenVec<T> {
Expand Down Expand Up @@ -606,6 +615,14 @@ impl<T: Clone> Clone for FrozenVec<T> {
}
}

impl<T: PartialEq> PartialEq for FrozenVec<T> {
fn eq(&self, other: &Self) -> bool {
let self_ref: &Vec<T> = &self.vec.read().unwrap();
let other_ref: &Vec<T> = &other.vec.read().unwrap();
self_ref == other_ref
}
}

// The context for these functions is that we want to have a
// series of exponentially increasing buffer sizes. We want
// to maximize the total size of the buffers (since this
Expand Down Expand Up @@ -1057,3 +1074,11 @@ impl<K: Clone, V: Clone> Clone for FrozenBTreeMap<K, V> {
Self(self.0.read().unwrap().clone().into())
}
}

impl<K: PartialEq, V: PartialEq> PartialEq for FrozenBTreeMap<K, V> {
fn eq(&self, other: &Self) -> bool {
let self_ref: &BTreeMap<K, V> = &self.0.read().unwrap();
let other_ref: &BTreeMap<K, V> = &other.0.read().unwrap();
self_ref == other_ref
}
}
9 changes: 9 additions & 0 deletions src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,15 @@ impl<'a, T: StableDeref> IntoIterator for &'a FrozenVec<T> {
}
}

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

#[test]
fn test_iteration() {
let vec = vec!["a", "b", "c", "d"];
Expand Down

0 comments on commit a2b1fe4

Please sign in to comment.