Datacake CRDT
An implementation of Riak's ORSWOT CRDT which is a CRDT which allows for removal of old
tombstones once a new event has been observed.
The set is built upon the second supported structure HLCTimestamp which is a Hybrid Logical Clock
which guarantees the timestamp will always be unique and monotonic (providing it's used correctly.)
Basic Example
use std::time::Duration;
use datacake_crdt::{OrSWotSet, HLCTimestamp};
fn main() {
let mut node_a = HLCTimestamp::now(0, 0);
let mut node_b = HLCTimestamp::new(node_a.datacake_timestamp() + Duration::from_secs(5), 0, 1);
let mut node_a_set = OrSWotSet::default();
let mut node_b_set = OrSWotSet::default();
node_a_set.insert(1, node_a.send().unwrap());
node_b_set.insert(2, node_b.send().unwrap());
std::thread::sleep(Duration::from_millis(500));
node_a_set.delete(1, node_a.send().unwrap());
node_b_set.merge(node_a_set.clone());
node_a_set.merge(node_b_set.clone());
assert!(node_a_set.get(&1).is_none(), "Key should be correctly removed.");
assert!(node_b_set.get(&1).is_none(), "Key should be correctly removed.");
}
Inspirations