pub struct TwoPSet<T: Ord + Clone> { /* private fields */ }Expand description
A two-phase set (2P-Set).
Elements can be added and removed, but once removed, they cannot be re-added. This is implemented with two G-Sets: one for additions and one for removals (tombstones).
§Example
use crdt_kit::prelude::*;
let mut s1 = TwoPSet::new();
s1.insert("apple");
s1.insert("banana");
s1.remove(&"banana");
assert!(s1.contains(&"apple"));
assert!(!s1.contains(&"banana")); // removed
let mut s2 = TwoPSet::new();
s2.insert("banana"); // trying to re-add on another replica
s1.merge(&s2);
assert!(!s1.contains(&"banana")); // still removed (tombstone wins)Implementations§
Source§impl<T: Ord + Clone> TwoPSet<T>
impl<T: Ord + Clone> TwoPSet<T>
Sourcepub fn insert(&mut self, value: T) -> bool
pub fn insert(&mut self, value: T) -> bool
Insert an element.
Returns true if the element was newly added (not previously
removed). If the element was already removed, it cannot be re-added
and this returns false.
Sourcepub fn remove(&mut self, value: &T) -> bool
pub fn remove(&mut self, value: &T) -> bool
Remove an element.
The element must have been added first. Once removed, it can never
be re-added. Returns true if the element was present and is now removed.
Trait Implementations§
impl<T: Eq + Ord + Clone> Eq for TwoPSet<T>
impl<T: Ord + Clone> StructuralPartialEq for TwoPSet<T>
Auto Trait Implementations§
impl<T> Freeze for TwoPSet<T>
impl<T> RefUnwindSafe for TwoPSet<T>where
T: RefUnwindSafe,
impl<T> Send for TwoPSet<T>where
T: Send,
impl<T> Sync for TwoPSet<T>where
T: Sync,
impl<T> Unpin for TwoPSet<T>
impl<T> UnwindSafe for TwoPSet<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more