Skip to content

Commit

Permalink
feat: implement PartialEq for LockFreeFrozenVec
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Sep 24, 2023
1 parent c5840c1 commit 859c2a3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,26 @@ impl<T: Copy> LockFreeFrozenVec<T> {
}
}

impl<T: Copy + PartialEq> PartialEq for LockFreeFrozenVec<T> {
fn eq(&self, other: &Self) -> bool {
// first check the length
let self_len = self.len.load(Ordering::Acquire);
let other_len = other.len.load(Ordering::Acquire);
if self_len != other_len {
return false;
}

// since the lengths are the same, just check the elements in order
for index in 0..self_len {
// the indices are in bounds, so this is safe
if unsafe { self.get_unchecked(index) } != unsafe { other.get_unchecked(index) } {
return false;
}
}
return true;
}
}

#[test]
fn test_non_lockfree_unchecked() {
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
Expand Down

0 comments on commit 859c2a3

Please sign in to comment.