Diamond Types Extended
High-performance CRDTs (Conflict-free Replicated Data Types) for collaborative applications.
Diamond Types Extended is a fork of diamond-types with extended types and a unified API.
Features
- Map - Key-value container with LWW (Last-Writer-Wins) registers per key
- Text - Sequence CRDT for collaborative text editing
- Set - OR-Set (Observed-Remove) with add-wins semantics
- Register - Single-value LWW container
- Nesting - All types can be nested within Maps
- Replication - Efficient sync between peers
Quick Start
use ;
// Create a document
let mut doc = new;
let alice = doc.get_or_create_agent;
// All mutations happen in transactions
doc.transact;
// Work with nested text
doc.transact;
// Read values directly
assert_eq!;
assert_eq!;
Replication
use ;
let mut doc_a = new;
let mut doc_b = new;
let alice = doc_a.get_or_create_agent;
let bob = doc_b.get_or_create_agent;
// Alice makes changes
doc_a.transact;
// Sync to Bob
let ops = doc_a.ops_since.into_owned;
doc_b.merge_ops.unwrap;
// Bob now has Alice's changes
assert!;
Conflict Resolution
Diamond Types Extended uses deterministic conflict resolution:
- Maps: LWW (Last-Writer-Wins) based on
(lamport_timestamp, agent_id)ordering - Sets: Add-wins semantics (concurrent add + remove = add wins)
- Text: Interleaving based on operation ordering
You can detect and handle conflicts explicitly:
let conflicted = doc.root.get_conflicted.unwrap;
if conflicted.has_conflicts
Performance
Diamond Types Extended inherits diamond-types' exceptional performance:
- Run-length encoded operation storage
- Optimized causal graph tracking
- The "egwalker" merge algorithm
See the original diamond-types blog post for benchmarks.
Attribution
Diamond Types Extended is built on diamond-types by Joseph Gentle (@josephg).
See ATTRIBUTION.md for full credits.
License
ISC License - see LICENSE for details.