use std::fmt::Debug;
use super::{Cmrdt, Dot, VClock};
#[derive(Debug, PartialEq, Eq)]
pub struct ReadCtx<V, A: Ord> {
pub add_clock: VClock<A>,
pub rm_clock: VClock<A>,
pub val: V,
}
#[derive(Debug)]
pub struct AddCtx<A: Ord> {
pub clock: VClock<A>,
pub dot: Dot<A>,
}
#[derive(Debug, Clone)]
pub struct RmCtx<A: Ord> {
pub clock: VClock<A>,
}
impl<V, A: Ord + Clone + Debug> ReadCtx<V, A> {
#[inline]
pub fn derive_add_ctx(self, actor: A) -> AddCtx<A> {
let mut clock = self.add_clock;
let dot = clock.inc(actor);
clock.apply(dot.clone());
AddCtx { clock, dot }
}
#[inline]
pub fn derive_rm_ctx(self) -> RmCtx<A> {
RmCtx {
clock: self.rm_clock,
}
}
#[inline]
pub fn split(self) -> (V, ReadCtx<(), A>) {
(
self.val,
ReadCtx {
add_clock: self.add_clock,
rm_clock: self.rm_clock,
val: (),
},
)
}
}