Skip to content

Commit

Permalink
Merge pull request #62 from aminya/eq
Browse files Browse the repository at this point in the history
feat: implement PartialEq for LockFreeFrozenVec
  • Loading branch information
Manishearth authored Oct 24, 2023
2 parents 692b89b + 2dd067f commit 1380764
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 @@ -841,6 +841,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 {
// This is safe because the indices are in bounds (for `LockFreeFrozenVec` the bounds can only grow).
if self.get(index) != other.get(index) {
return false;
}
}
return true;
}
}

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

0 comments on commit 1380764

Please sign in to comment.