pub struct TwoPhaseSet<X: Clone + Eq + Hash> {
pub added: HashSet<X>,
pub removed: HashSet<X>,
}Expand description
A set that can add or delete values
§Panics
Any attempt to del an element that one did not previously add will panic:
ⓘ
// this will panic
use std::collections::HashSet;
use cvrdt_exposition::{Grow, Shrink, TwoPhaseSet};
let mut x = TwoPhaseSet::new((HashSet::new(), HashSet::new()));
x.del("this will panic");§Examples
Example usage, including demonstrating some properties:
use std::collections::HashSet;
use cvrdt_exposition::{Grow, Shrink, TwoPhaseSet};
let mut x = TwoPhaseSet::new((HashSet::new(), HashSet::new()));
for c in "abc".chars() {
x.add(c);
}
x.del('c');
assert_eq!(x.query(&'a'), true);
assert_eq!(x.query(&'z'), false);
assert_eq!(x.query(&'c'), false);
let y = TwoPhaseSet::new(("abcdef".chars().collect(), HashSet::new()));
assert_eq!(x.merge(&y).payload(), y.merge(&x).payload());
let z = TwoPhaseSet::new(("8675309abcdefg".chars().collect(), "toremove".chars().collect()));
assert_eq!(x.merge(&y.merge(&z)).payload(), x.merge(&y).merge(&z).payload());Fields§
§added: HashSet<X>The elements that have been added to this set
removed: HashSet<X>The elements that have been removed from this set
Trait Implementations§
Source§impl<X: Clone + Clone + Eq + Hash> Clone for TwoPhaseSet<X>
impl<X: Clone + Clone + Eq + Hash> Clone for TwoPhaseSet<X>
Source§fn clone(&self) -> TwoPhaseSet<X>
fn clone(&self) -> TwoPhaseSet<X>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<X: Clone + Eq + Hash> Grow for TwoPhaseSet<X>
impl<X: Clone + Eq + Hash> Grow for TwoPhaseSet<X>
Source§type Payload = (HashSet<X>, HashSet<X>)
type Payload = (HashSet<X>, HashSet<X>)
The internal state of our
CvRDT; sufficient to build a new copy via new.
Required to implement Eq for testing and verification.Source§fn add(&mut self, update: Self::Update)
fn add(&mut self, update: Self::Update)
Add an item to the data structure, mutating this
CvRDT in place Read moreSource§fn le(&self, other: &Self) -> bool
fn le(&self, other: &Self) -> bool
Is this
CvRDT ≤ another in the semilattice’s partial order? Read moreAuto Trait Implementations§
impl<X> Freeze for TwoPhaseSet<X>
impl<X> RefUnwindSafe for TwoPhaseSet<X>where
X: RefUnwindSafe,
impl<X> Send for TwoPhaseSet<X>where
X: Send,
impl<X> Sync for TwoPhaseSet<X>where
X: Sync,
impl<X> Unpin for TwoPhaseSet<X>where
X: Unpin,
impl<X> UnsafeUnpin for TwoPhaseSet<X>
impl<X> UnwindSafe for TwoPhaseSet<X>where
X: UnwindSafe,
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