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
use Borrow;
use Ord;
use BTreeMap;
use BTreeSet;
// use crate::{AnnotatedOp, CRDT, OpMetadata};
//
// pub struct ORSet<T, A> {
// set: BTreeMap<A, BTreeSet<T>>,
// }
//
// pub enum ORSetOp<T, A> {
// Insert {
// value: A,
// },
// Remove {
// value: A,
// tags: BTreeSet<T>,
// },
// }
//
// // TODO: CausalOrder for ORSetOp?
//
// impl<T, A> ORSet<T, A> {
// pub fn contains<Q>(&self, value:&Q) -> bool
// where
// A: Borrow<Q> + Ord,
// Q: Ord,
// {
// self.set.contains_key(value)
// }
// }
//
// // TODO: Iter, len, is_subset, is_superset, ...
//
// impl<M:OpMetadata + OpMetadata<Time = T>, T:Ord, A:Clone + Ord> CRDT<M> for ORSet<T, A> {
// type Op = ORSetOp<T, A>;
//
// fn apply<'a>(&'a mut self, op: &'a AnnotatedOp<M, Self::Op>) {
// match &op.operation {
// ORSetOp::Insert {value} => {
// // If the value already exists, insert this operation's id/time into its set.
// if let Some(tags) = self.set.get_mut(value) {
// let inserted = tags.insert(op.metadata.time());
// assert!(inserted, "Precondition violated: An operation was applied more than once.");
// // Otherwise, insert the value into the map.
// } else {
// self.set.insert(value.clone(), BTreeSet::from([op.metadata.time()]));
// }
// }
// ORSetOp::Remove {value, tags} => {
// // If the value already exists, remove the specified tags.
// if let Some(current_tags) = self.set.get_mut(value) {
// // TODO: We should probably check that they all existed in the set before
// // deletion.
// current_tags.retain(|t| !tags.contains(t));
// } else {
// panic!("Precondition violated: Attempting to remove an operation that does not exist.");
// }
// }
// }
// }
// }
//