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>

source§

fn clone(&self) -> TwoPhaseSet<X>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<X: Debug + Clone + Eq + Hash> Debug for TwoPhaseSet<X>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<X: Clone + Eq + Hash> Grow for TwoPhaseSet<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.
§

type Update = X

Message to update our internal state
§

type Query = X

Message to query the Value of our CvRDT
§

type Value = bool

The response to a Query
source§

fn new(payload: Self::Payload) -> Self

Create a new version of our data structure from the given Payload Read more
source§

fn payload(&self) -> Self::Payload

Retrieve the Payload (internal state) of this CvRDT Read more
source§

fn add(&mut self, update: Self::Update)

Add an item to the data structure, mutating this CvRDT in place Read more
source§

fn le(&self, other: &Self) -> bool

Is this CvRDT ≤ another in the semilattice’s partial order? Read more
source§

fn merge(&self, other: &Self) -> Self

Merge this data structure and another into a new CvRDT Read more
source§

fn query(&self, query: &Self::Query) -> Self::Value

Query the data structure to get some Value Read more
source§

impl<X: Clone + Eq + Hash> Shrink for TwoPhaseSet<X>

source§

fn del(&mut self, x: X)

Delete an item from the data structure, mutating this CvRDT in place Read more

Auto 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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.