Struct cvrdt_exposition::two_phase_set::TwoPhaseSet
source · 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 copy of the value. Read more
1.0.0 · 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>
§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> 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> 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