pub struct AWMap<K: Ord + Clone, V: Clone + Eq> { /* private fields */ }Expand description
An add-wins map (AW-Map).
A key-value map where each key is tracked with OR-Set semantics: concurrent add and remove of the same key resolves in favor of add. Values are updated using a causal version vector per key.
§Example
use crdt_kit::prelude::*;
let mut m1 = AWMap::new(1);
m1.insert("color", "red");
let mut m2 = AWMap::new(2);
m2.insert("color", "blue");
m1.merge(&m2);
// Both adds are concurrent — the latest by tag ordering wins
assert!(m1.contains_key(&"color"));Implementations§
Source§impl<K: Ord + Clone, V: Clone + Eq> AWMap<K, V>
impl<K: Ord + Clone, V: Clone + Eq> AWMap<K, V>
Sourcepub fn insert(&mut self, key: K, value: V)
pub fn insert(&mut self, key: K, value: V)
Insert or update a key-value pair.
Generates a unique tag for this write. If the key already exists, the old tags are kept (they accumulate until a remove clears them). The value is updated to the new value.
Sourcepub fn remove(&mut self, key: &K) -> bool
pub fn remove(&mut self, key: &K) -> bool
Remove a key from the map.
Only removes the tags that this replica has observed. Concurrent inserts on other replicas will survive the merge (add wins).
Returns true if the key was present and removed.
Sourcepub fn contains_key(&self, key: &K) -> bool
pub fn contains_key(&self, key: &K) -> bool
Check if a key is present in the map.
Trait Implementations§
Source§impl<K: Ord + Clone, V: Clone + Eq> DeltaCrdt for AWMap<K, V>
impl<K: Ord + Clone, V: Clone + Eq> DeltaCrdt for AWMap<K, V>
Source§type Delta = AWMapDelta<K, V>
type Delta = AWMapDelta<K, V>
The type of delta produced by this CRDT.
Source§fn delta(&self, other: &Self) -> AWMapDelta<K, V>
fn delta(&self, other: &Self) -> AWMapDelta<K, V>
Source§fn apply_delta(&mut self, delta: &AWMapDelta<K, V>)
fn apply_delta(&mut self, delta: &AWMapDelta<K, V>)
Apply a delta to this replica’s state. Read more
impl<K: Eq + Ord + Clone, V: Eq + Clone + Eq> Eq for AWMap<K, V>
impl<K: Ord + Clone, V: Clone + Eq> StructuralPartialEq for AWMap<K, V>
Auto Trait Implementations§
impl<K, V> Freeze for AWMap<K, V>
impl<K, V> RefUnwindSafe for AWMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
impl<K, V> Send for AWMap<K, V>
impl<K, V> Sync for AWMap<K, V>
impl<K, V> Unpin for AWMap<K, V>
impl<K, V> UnsafeUnpin for AWMap<K, V>
impl<K, V> UnwindSafe for AWMap<K, V>where
K: RefUnwindSafe,
V: RefUnwindSafe,
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
Mutably borrows from an owned value. Read more