Struct ditto::map::Map
[−]
[src]
pub struct Map<K: Key, V: Value> { /* fields omitted */ }
A Map is a HashMap
-like collection of key-value pairs.
As with HashMap
, Map
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, Map is based on 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.
Map's performance characteristics are similar to HashMap
:
insert
: O(1)remove
: O(1)contains_key
: O(1)get
: O(1)execute_op
: O(1)merge
: O(N1 + N2 + S1 + S2), where N1 and N2 are the number of values in the maps being merged, and S1 and S2 are the number of sites that have edited maps being merged.
Methods
impl<K: Key, V: Value> Map<K, V>
[src]
pub fn new() -> Self
[src]
Constructs and returns a new map. The map has site id 1.
pub fn contains_key(&self, key: &K) -> bool
[src]
Returns true iff the map has the key.
pub fn get(&self, key: &K) -> Option<&V>
[src]
Returns a reference to the value corresponding to the key.
pub fn insert(&mut self, key: K, value: V) -> Result<Op<K, V>, Error>
[src]
Inserts a key-value pair into the map and returns a remote
op that can be sent to remote sites for replication. If the
map does not have a site allocated, it caches the op and
returns an AwaitingSite
error.
pub fn remove(&mut self, key: &K) -> Option<Result<Op<K, V>, Error>>
[src]
Removes a key from the map and returns a remote op
that can be sent to remote sites for replication.
If the map 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) -> MapState<K, V>
[src]
Returns a borrowed CRDT state.
pub fn clone_state(&self) -> MapState<'static, K, V>
[src]
Returns an owned CRDT state of cloned values.
pub fn into_state(self) -> MapState<'static, K, V>
[src]
Consumes the CRDT and returns its state
pub fn from_state(
state: MapState<K, V>,
site_id: Option<SiteId>
) -> Result<Self, Error>
[src]
state: MapState<K, V>,
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) -> HashMap<K, V>
[src]
Returns the CRDT value's equivalent local value.
pub fn execute_op(&mut self, op: Op<K, V>) -> LocalOp<K, V>
[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<K, V>,
site_id: SiteId
) -> Result<LocalOp<K, V>, Error>
[src]
&mut self,
op: Op<K, V>,
site_id: SiteId
) -> Result<LocalOp<K, V>, 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: MapState<K, V>) -> 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<K, V>>, 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<K: Debug + Key, V: Debug + Value> Debug for Map<K, V>
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<K: Clone + Key, V: Clone + Value> Clone for Map<K, V>
[src]
fn clone(&self) -> Map<K, V>
[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
impl<K: PartialEq + Key, V: PartialEq + Value> PartialEq for Map<K, V>
[src]
fn eq(&self, __arg_0: &Map<K, V>) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Map<K, V>) -> bool
[src]
This method tests for !=
.