Struct garage_table::crdt::Map
source · pub struct Map<K, V> { /* private fields */ }
Expand description
Simple CRDT Map
This types defines a CRDT for a map from keys to values. Values are CRDT types which can have their own updating logic.
Internally, the map is stored as a vector of keys and values, sorted by ascending key order.
This is why the key type K
must implement Ord
(and also to ensure a unique serialization,
such that two values can be compared for equality based on their hashes). As a consequence,
insertions take O(n)
time. This means that Map should be used for reasonably small maps.
However, note that even if we were using a more efficient data structure such as a BTreeMap
,
the serialization cost O(n)
would still have to be paid at each modification, so we are
actually not losing anything here.
Implementations§
source§impl<K, V> Map<K, V>
impl<K, V> Map<K, V>
sourcepub fn put_mutator(k: K, v: V) -> Map<K, V>
pub fn put_mutator(k: K, v: V) -> Map<K, V>
Returns a map that contains a single mapping from the specified key to the specified value. This can be used to build a delta-mutator: when merged with another map, the value will be added or CRDT-merged if a previous value already exists.
Trait Implementations§
source§impl<'de, K, V> Deserialize<'de> for Map<K, V>where
K: Deserialize<'de>,
V: Deserialize<'de>,
impl<'de, K, V> Deserialize<'de> for Map<K, V>where
K: Deserialize<'de>,
V: Deserialize<'de>,
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<Map<K, V>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Map<K, V>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl<K, V> FromIterator<(K, V)> for Map<K, V>
impl<K, V> FromIterator<(K, V)> for Map<K, V>
A crdt map can be created from an iterator of key-value pairs. Note that all keys in the iterator must be distinct: this function will throw a panic if it is not the case.
source§impl<K, V> PartialEq for Map<K, V>
impl<K, V> PartialEq for Map<K, V>
source§impl<K, V> Serialize for Map<K, V>
impl<K, V> Serialize for Map<K, V>
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl<K, V> Eq for Map<K, V>
impl<K, V> StructuralPartialEq for Map<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for Map<K, V>
impl<K, V> RefUnwindSafe for Map<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for Map<K, V>
impl<K, V> Sync for Map<K, V>
impl<K, V> Unpin for Map<K, V>
impl<K, V> UnwindSafe for Map<K, V>where
K: UnwindSafe,
V: 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
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.