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]

[src]

Constructs and returns a new map. The map has site id 1.

[src]

Returns true iff the map has the key.

[src]

Returns a reference to the value corresponding to the key.

[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.

[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.

[src]

Returns the site id.

[src]

Returns a borrowed CRDT state.

[src]

Returns an owned CRDT state of cloned values.

[src]

Consumes the CRDT and returns its state

[src]

Constructs a new CRDT from a state and optional site id. If the site id is present, it must be nonzero.

[src]

Returns the CRDT value's equivalent local value.

[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.

[src]

Validates that an op only inserts elements from a given site id, then executes the op and returns the equivalent local op.

[src]

Merges a remote CRDT state into the CRDT. The remote CRDT state must have a site id.

[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]

[src]

Formats the value using the given formatter. Read more

impl<K: Clone + Key, V: Clone + Value> Clone for Map<K, V>
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<K: PartialEq + Key, V: PartialEq + Value> PartialEq for Map<K, V>
[src]

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

impl<K: Key, V: Value> From<HashMap<K, V>> for Map<K, V>
[src]

[src]

Performs the conversion.

Auto Trait Implementations

impl<K, V> Send for Map<K, V> where
    K: Send,
    V: Send

impl<K, V> Sync for Map<K, V> where
    K: Sync,
    V: Sync