Introduce undo/redo support for arbitrary operations in Buffer

This commit is contained in:
Antonio Scandurra 2021-04-07 19:56:15 +02:00
parent 57a3207897
commit 44ab38ac98
2 changed files with 287 additions and 76 deletions

View file

@ -5,10 +5,12 @@ use std::ops::{Add, AddAssign};
use std::sync::Arc;
pub type ReplicaId = u16;
pub type Seq = u64;
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq, Ord, PartialOrd)]
pub struct Local {
pub replica_id: ReplicaId,
pub value: u64,
pub value: Seq,
}
#[derive(Clone, Debug, Eq, PartialEq)]
@ -16,7 +18,7 @@ pub struct Global(Arc<HashMap<ReplicaId, u64>>);
#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Lamport {
pub value: u64,
pub value: Seq,
pub replica_id: ReplicaId,
}
@ -62,7 +64,7 @@ impl Global {
Global(Arc::new(HashMap::new()))
}
pub fn get(&self, replica_id: ReplicaId) -> u64 {
pub fn get(&self, replica_id: ReplicaId) -> Seq {
*self.0.get(&replica_id).unwrap_or(&0)
}