Implement anchors using an offset + a version vector

This commit is contained in:
Antonio Scandurra
2021-06-01 15:28:20 +02:00
parent 311e1b0f5e
commit da7e3c8cd8
4 changed files with 273 additions and 293 deletions
+15 -1
View File
@@ -81,12 +81,26 @@ impl Global {
}
}
pub fn observe_all(&mut self, other: &Self) {
pub fn join(&mut self, other: &Self) {
for timestamp in other.0.iter() {
self.observe(*timestamp);
}
}
pub fn meet(&mut self, other: &Self) {
for timestamp in other.0.iter() {
if let Some(entry) = self
.0
.iter_mut()
.find(|t| t.replica_id == timestamp.replica_id)
{
entry.value = cmp::min(entry.value, timestamp.value);
} else {
self.0.push(*timestamp);
}
}
}
pub fn observed(&self, timestamp: Local) -> bool {
self.get(timestamp.replica_id) >= timestamp.value
}