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
//! # 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
//! ```rust
//! use std::time::Duration;
//! use datacake_crdt::{OrSWotSet, HLCTimestamp};
//!
//! let mut node_a = HLCTimestamp::now(0, 0);
//!
//! // Simulating a node begin slightly ahead.
//! let mut node_b = HLCTimestamp::new(node_a.datacake_timestamp() + Duration::from_secs(5), 0, 1);
//!
//! // We only have one effective source here.
//! let mut node_a_set = OrSWotSet::<1>::default();
//! let mut node_b_set = OrSWotSet::<1>::default();
//!
//! // Insert a new key with a new timestamp in set A.
//! node_a_set.insert(1, node_a.send().unwrap());
//!
//! // Insert a new entry in set B.
//! node_b_set.insert(2, node_b.send().unwrap());
//!
//! // Let some time pass for demonstration purposes.
//! std::thread::sleep(Duration::from_millis(500));
//!
//! // Set A has key `1` removed.
//! node_a_set.delete(1, node_a.send().unwrap());
//!
//! // Merging set B with set A and vice versa.
//! // Our sets are now aligned without conflicts.
//! node_b_set.merge(node_a_set.clone());
//! node_a_set.merge(node_b_set.clone());
//!
//! // Set A and B should both see that key `1` has been deleted.
//! 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
//! - [CRDTs for Mortals by James Long](https://www.youtube.com/watch?v=iEFcmfmdh2w)
//! - [Big(ger) Sets: Making CRDT Sets Scale in Riak by Russell Brown](https://www.youtube.com/watch?v=f20882ZSdkU)
//! - ["CRDTs Illustrated" by Arnout Engelen](https://www.youtube.com/watch?v=9xFfOhasiOE)
pub use BadState;
pub use ;
pub use ;