Skip to main content

AWMap

Struct AWMap 

Source
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>

Source

pub fn new(actor: NodeId) -> Self

Create a new empty AW-Map for the given node.

Source

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.

Source

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.

Source

pub fn get(&self, key: &K) -> Option<&V>

Get the value associated with a key, if present.

Source

pub fn contains_key(&self, key: &K) -> bool

Check if a key is present in the map.

Source

pub fn len(&self) -> usize

Get the number of keys in the map.

Source

pub fn is_empty(&self) -> bool

Check if the map is empty.

Source

pub fn iter(&self) -> impl Iterator<Item = (&K, &V)>

Iterate over key-value pairs.

Source

pub fn keys(&self) -> impl Iterator<Item = &K>

Get all keys.

Source

pub fn values(&self) -> impl Iterator<Item = &V>

Get all values.

Source

pub fn actor(&self) -> NodeId

Get this replica’s node ID.

Trait Implementations§

Source§

impl<K: Clone + Ord + Clone, V: Clone + Clone + Eq> Clone for AWMap<K, V>

Source§

fn clone(&self) -> AWMap<K, V>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Ord + Clone, V: Clone + Eq> Crdt for AWMap<K, V>

Source§

fn merge(&mut self, other: &Self)

Merge another replica’s state into this one. Read more
Source§

impl<K: Debug + Ord + Clone, V: Debug + Clone + Eq> Debug for AWMap<K, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K: Ord + Clone, V: Clone + Eq> DeltaCrdt for AWMap<K, V>

Source§

type Delta = AWMapDelta<K, V>

The type of delta produced by this CRDT.
Source§

fn delta(&self, other: &Self) -> AWMapDelta<K, V>

Generate a delta containing changes in self that other does not have. Read more
Source§

fn apply_delta(&mut self, delta: &AWMapDelta<K, V>)

Apply a delta to this replica’s state. Read more
Source§

impl<K: Ord + Clone, V: Clone + Eq> IntoIterator for AWMap<K, V>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<(K, V)>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K: PartialEq + Ord + Clone, V: PartialEq + Clone + Eq> PartialEq for AWMap<K, V>

Source§

fn eq(&self, other: &AWMap<K, V>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K: Ord + Clone, V: Clone + Eq> Versioned for AWMap<K, V>

Source§

const CURRENT_VERSION: u8 = 1

Current schema version for this CRDT type’s serialization format.
Source§

const CRDT_TYPE: CrdtType = CrdtType::AWMap

The CRDT type identifier for the envelope.
Source§

impl<K: Eq + Ord + Clone, V: Eq + Clone + Eq> Eq for AWMap<K, V>

Source§

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>

§

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

§

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

§

impl<K, V> Unpin for AWMap<K, V>

§

impl<K, V> UnsafeUnpin for AWMap<K, V>

§

impl<K, V> UnwindSafe for AWMap<K, V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.