pub struct LWW<T> {
pub value: T,
pub ts: u64,
pub replica: u64,
}Expand description
A Last-Writer-Wins register lattice.
The state is a triple (value, ts, replica) where ts is a logical
timestamp (e.g. Lamport clock, HLC, or monotone counter) and replica
is a unique identifier for the writer. Ordering uses (ts, replica)
lexicographically, yielding a total order on register versions; join
returns the greater version and is commutative, associative, and
idempotent.
This makes LWW<T> a simple register-style lattice that can be used
as the payload in higher-level CRDTs or accumulators where “latest
value” semantics are needed.
§Properties
- Commutative:
a.join(b) == b.join(a) - Associative:
a.join(b).join(c) == a.join(b.join(c)) - Idempotent:
a.join(a) == a
§Use Cases
- Distributed caches (last-write-wins per key)
- Configuration management (latest config wins)
- Watermark tracking where ranks can report decreasing values (failure recovery, reprocessing)
§Example
use algebra::JoinSemilattice;
use algebra::LWW;
// Two writers (replicas 1 and 2) with different timestamps
let v1 = LWW::new(100, 1, 1);
let v2 = LWW::new(50, 2, 2);
// Higher timestamp wins, even if value is smaller
assert_eq!(v1.join(&v2), LWW::new(50, 2, 2));Fields§
§value: TThe current value of the register.
ts: u64The logical timestamp associated with this value.
replica: u64The replica ID of the writer (for deterministic tie-breaking).
Implementations§
Trait Implementations§
Source§impl<T: Clone + PartialEq + Default> BoundedJoinSemilattice for LWW<T>
impl<T: Clone + PartialEq + Default> BoundedJoinSemilattice for LWW<T>
Source§fn join_all_from_bottom<I>(it: I) -> Selfwhere
I: IntoIterator<Item = Self>,
fn join_all_from_bottom<I>(it: I) -> Selfwhere
I: IntoIterator<Item = Self>,
Join a finite iterator of values, starting from ⊥. Read more
Source§impl<'de, T> Deserialize<'de> for LWW<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for LWW<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T: Clone + PartialEq> JoinSemilattice for LWW<T>
impl<T: Clone + PartialEq> JoinSemilattice for LWW<T>
Source§fn join_assign(&mut self, other: &Self)
fn join_assign(&mut self, other: &Self)
In-place variant.
Source§fn leq(&self, other: &Self) -> boolwhere
Self: PartialEq,
fn leq(&self, other: &Self) -> boolwhere
Self: PartialEq,
Derived partial order: x ≤ y iff x ⊔ y = y.
Source§fn join_all<I>(it: I) -> Option<Self>where
I: IntoIterator<Item = Self>,
fn join_all<I>(it: I) -> Option<Self>where
I: IntoIterator<Item = Self>,
Join a finite iterator of values. Returns
None for empty
iterators.impl<T: Copy> Copy for LWW<T>
impl<T: Eq> Eq for LWW<T>
impl<T> StructuralPartialEq for LWW<T>
Auto Trait Implementations§
impl<T> Freeze for LWW<T>where
T: Freeze,
impl<T> RefUnwindSafe for LWW<T>where
T: RefUnwindSafe,
impl<T> Send for LWW<T>where
T: Send,
impl<T> Sync for LWW<T>where
T: Sync,
impl<T> Unpin for LWW<T>where
T: Unpin,
impl<T> UnwindSafe for LWW<T>where
T: 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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more