1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! MDCS Delta - Delta-state CRDT machinery
//!
//! This crate implements the δ-CRDT framework including:
//! - Delta buffers for grouping and batching
//! - Delta-mutators for each CRDT type
//! - Anti-entropy Algorithm 1 (convergence mode)
//! - Anti-entropy Algorithm 2 (causal consistency mode)
//!
//! # δ-CRDT Framework
//!
//! The δ-CRDT (delta-state CRDT) framework provides efficient synchronization
//! by only transmitting the changes (deltas) rather than full state.
//!
//! ## Key Concepts
//!
//! - **Delta-mutator**: A function `mδ` such that `m(X) = X ⊔ mδ(X)`
//! - **Delta buffer**: Accumulates deltas for batched transmission
//! - **Anti-entropy**: Protocol for eventually consistent synchronization
//!
//! ## Algorithm 1: Convergence Mode
//!
//! Guarantees eventual convergence without causal ordering.
//!
//! ```text
//! On local mutation m:
//! d = mδ(X) // compute delta
//! X = X ⊔ d // apply to local state
//! D.push(d) // buffer for sending
//!
//! On send to peer j:
//! send D[acked[j]..] to j
//!
//! On receive delta d from peer i:
//! X = X ⊔ d // apply (idempotent!)
//! send ack(seq) to i
//! ```
//!
//! ## Algorithm 2: Causal Consistency Mode
//!
//! Guarantees causal ordering of delta delivery using delta-intervals.
//!
//! ```text
//! Durable state: (Xᵢ, cᵢ) - survives crashes
//! Volatile state: (Dᵢ, Aᵢ) - lost on crash
//!
//! On local mutation m:
//! cᵢ := cᵢ + 1
//! d := mδ(Xᵢ)
//! Xᵢ := Xᵢ ⊔ d
//! ∀j: Dᵢ[j] := Dᵢ[j] ⊔ d
//!
//! On send to peer j:
//! send ⟨Dᵢ[j], Aᵢ[j]+1, cᵢ⟩ to j
//!
//! On receive ⟨d, n, m⟩ from peer j:
//! if n = Aᵢ[j] + 1 then // causally ready
//! Xᵢ := Xᵢ ⊔ d
//! Aᵢ[j] := m
//! send ack(m) to j
//! else
//! buffer for later
//! ```
//!
//! # Example
//!
//! ```rust,ignore
//! use mdcs_delta::buffer::DeltaReplica;
//! use mdcs_core::gset::GSet;
//!
//! let mut replica: DeltaReplica<GSet<i32>> = DeltaReplica::new("replica1");
//!
//! // Mutate using delta-mutator
//! replica.mutate(|_state| {
//! let mut delta = GSet::new();
//! delta.insert(42);
//! delta
//! });
//!
//! assert!(replica.state().contains(&42));
//! ```
// Re-export main types for convenience
pub use ;
pub use ;
pub use ;
pub use ;