Struct ditto::set::Set
[−]
[src]
pub struct Set<T: SetElement> { /* fields omitted */ }
A Set is a HashSet
-like collection of distinct elements.
As with HashSet
, Set
requires that the elements implement
the Eq
and Hash
traits. To allow for CRDT replication, they
must also implement the Clone
, Serialize
, and Deserialize
traits.
Internally, Set is a variant of OR-Set. It allows op-based replication
via execute_op
and state-based replication
via merge
. State-based replication allows
out-of-order delivery but op-based replication does not.
Set
has a spatial complexity of O(N + S), where
N is the number of values concurrently held in the Set
and
S is the number of sites that have inserted values into the Set
.
It has the following performance characteristics:
insert
: O(1)remove
: O(1)contains
: O(1)execute_op
: O(1)merge
: O(N1 + N2 + S1 + S2), where N1 and N2 are the number of values in the sets being merged, and S1 and S2 are the number of sites that have edited sets being merged.
Methods
impl<T: SetElement> Set<T>
[src]
pub fn new() -> Self
[src]
Constructs and returns a new set CRDT. The set has site 1 and counter 0.
pub fn contains(&self, value: &T) -> bool
[src]
Returns true iff the set contains the value.
pub fn insert(&mut self, value: T) -> Result<Op<T>, Error>
[src]
Inserts a value into the set and returns a remote op
that can be sent to remote sites for replication.
If the set does not have a site allocated, it caches
the op and returns an AwaitingSite
error.
pub fn remove(&mut self, value: &T) -> Option<Result<Op<T>, Error>>
[src]
Removes a value from the set and returns a remote op
that can be sent to remote sites for replication.
If the set does not have a site allocated, it caches
the op and returns an AwaitingSite
error.
pub fn site_id(&self) -> SiteId
[src]
Returns the site id.
pub fn state(&self) -> SetState<T>
[src]
Returns a borrowed CRDT state.
pub fn clone_state(&self) -> SetState<'static, T>
[src]
Returns an owned CRDT state of cloned values.
pub fn into_state(self) -> SetState<'static, T>
[src]
Consumes the CRDT and returns its state
pub fn from_state(
state: SetState<T>,
site_id: Option<SiteId>
) -> Result<Self, Error>
[src]
state: SetState<T>,
site_id: Option<SiteId>
) -> Result<Self, Error>
Constructs a new CRDT from a state and optional site id. If the site id is present, it must be nonzero.
pub fn local_value(&self) -> HashSet<T>
[src]
Returns the CRDT value's equivalent local value.
pub fn execute_op(&mut self, op: Op<T>) -> Option<LocalOp<T>>
[src]
Executes an op and returns the equivalent local op.
This function assumes that the op always inserts values
from the correct site. For untrusted ops, used validate_and_execute_op
.
pub fn validate_and_execute_op(
&mut self,
op: Op<T>,
site_id: SiteId
) -> Result<Option<LocalOp<T>>, Error>
[src]
&mut self,
op: Op<T>,
site_id: SiteId
) -> Result<Option<LocalOp<T>>, Error>
Validates that an op only inserts elements from a given site id, then executes the op and returns the equivalent local op.
pub fn merge(&mut self, other: SetState<T>) -> Result<(), Error>
[src]
Merges a remote CRDT state into the CRDT. The remote CRDT state must have a site id.
pub fn add_site_id(&mut self, site_id: SiteId) -> Result<Vec<Op<T>>, Error>
[src]
Assigns a site id to the CRDT and returns any cached ops. If the CRDT already has a site id, it returns an error.
Trait Implementations
impl<T: Debug + SetElement> Debug for Set<T>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<T: Clone + SetElement> Clone for Set<T>
[src]
fn clone(&self) -> Set<T>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more