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

feat: implement PartialEq for LockFreeFrozenVec #62

Merged
merged 8 commits into from
Oct 24, 2023
20 changes: 20 additions & 0 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,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 {
aminya marked this conversation as resolved.
Show resolved Hide resolved
// 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
Loading