Rename `LClock` to `Lamport`

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
This commit is contained in:
Alexis Sellier 2022-11-26 17:48:50 +01:00
parent b79e2f5b56
commit fee0296910
No known key found for this signature in database
5 changed files with 27 additions and 26 deletions

View File

@ -3,10 +3,10 @@ use std::collections::BTreeMap;
use radicle_crypto::{PublicKey, Signature, Signer}; use radicle_crypto::{PublicKey, Signature, Signer};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::clock::LClock; use crate::clock::Lamport;
/// Identifies a change. /// Identifies a change.
pub type ChangeId = (LClock, ActorId); pub type ChangeId = (Lamport, ActorId);
/// The author of a change. /// The author of a change.
pub type ActorId = PublicKey; pub type ActorId = PublicKey;
@ -20,7 +20,7 @@ pub struct Change<A> {
/// The author of the change. /// The author of the change.
pub author: ActorId, pub author: ActorId,
/// Lamport clock. /// Lamport clock.
pub clock: LClock, pub clock: Lamport,
} }
impl<A> Change<A> { impl<A> Change<A> {
@ -63,20 +63,20 @@ pub struct Envelope {
#[derive(Default)] #[derive(Default)]
pub struct Actor<G, A> { pub struct Actor<G, A> {
pub signer: G, pub signer: G,
pub clock: LClock, pub clock: Lamport,
pub changes: BTreeMap<(LClock, PublicKey), Change<A>>, pub changes: BTreeMap<(Lamport, PublicKey), Change<A>>,
} }
impl<G: Signer, A: Clone + Serialize> Actor<G, A> { impl<G: Signer, A: Clone + Serialize> Actor<G, A> {
pub fn new(signer: G) -> Self { pub fn new(signer: G) -> Self {
Self { Self {
signer, signer,
clock: LClock::default(), clock: Lamport::default(),
changes: BTreeMap::default(), changes: BTreeMap::default(),
} }
} }
pub fn receive(&mut self, changes: impl IntoIterator<Item = Change<A>>) -> LClock { pub fn receive(&mut self, changes: impl IntoIterator<Item = Change<A>>) -> Lamport {
for change in changes { for change in changes {
let clock = change.clock; let clock = change.clock;
@ -89,7 +89,7 @@ impl<G: Signer, A: Clone + Serialize> Actor<G, A> {
/// Reset actor state to initial state. /// Reset actor state to initial state.
pub fn reset(&mut self) { pub fn reset(&mut self) {
self.changes.clear(); self.changes.clear();
self.clock = LClock::default(); self.clock = Lamport::default();
} }
/// Returned an ordered list of events. /// Returned an ordered list of events.

View File

@ -6,11 +6,11 @@ use crate::Semilattice as _;
/// Lamport clock. /// Lamport clock.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)] #[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)] #[serde(transparent)]
pub struct LClock { pub struct Lamport {
counter: Max<u64>, counter: Max<u64>,
} }
impl LClock { impl Lamport {
/// Return the clock value. /// Return the clock value.
pub fn get(&self) -> u64 { pub fn get(&self) -> u64 {
*self.counter.get() *self.counter.get()
@ -31,7 +31,7 @@ impl LClock {
} }
} }
impl From<u64> for LClock { impl From<u64> for Lamport {
fn from(counter: u64) -> Self { fn from(counter: u64) -> Self {
Self { Self {
counter: Max::from(counter), counter: Max::from(counter),

View File

@ -16,7 +16,7 @@ pub mod test;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
pub use change::*; pub use change::*;
pub use clock::LClock; pub use clock::Lamport;
pub use lwwmap::LWWMap; pub use lwwmap::LWWMap;
pub use lwwreg::LWWReg; pub use lwwreg::LWWReg;
pub use lwwset::LWWSet; pub use lwwset::LWWSet;

View File

@ -3,7 +3,8 @@ use std::str::FromStr;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use radicle_crdt as crdt; use radicle_crdt as crdt;
use radicle_crdt::{ChangeId, LClock, LWWReg, Max, Semilattice}; use radicle_crdt::clock;
use radicle_crdt::{ChangeId, LWWReg, Max, Semilattice};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use thiserror::Error; use thiserror::Error;
@ -73,10 +74,10 @@ impl Status {
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct Issue { pub struct Issue {
// TODO(cloudhead): Title should bias towards shorter strings. // TODO(cloudhead): Title should bias towards shorter strings.
title: LWWReg<Max<String>, LClock>, title: LWWReg<Max<String>, clock::Lamport>,
status: LWWReg<Max<Status>, LClock>, status: LWWReg<Max<Status>, clock::Lamport>,
thread: Thread, thread: Thread,
clock: LClock, clock: clock::Lamport,
} }
impl Semilattice for Issue { impl Semilattice for Issue {
@ -93,7 +94,7 @@ impl Default for Issue {
title: Max::from(String::default()).into(), title: Max::from(String::default()).into(),
status: Max::from(Status::default()).into(), status: Max::from(Status::default()).into(),
thread: Thread::default(), thread: Thread::default(),
clock: LClock::default(), clock: clock::Lamport::default(),
} }
} }
} }
@ -146,7 +147,7 @@ impl Issue {
self.thread.comments().map(|(id, comment)| (id, comment)) self.thread.comments().map(|(id, comment)| (id, comment))
} }
pub fn clock(&self) -> &LClock { pub fn clock(&self) -> &clock::Lamport {
&self.clock &self.clock
} }
@ -186,14 +187,14 @@ impl Deref for Issue {
pub struct IssueMut<'a, 'g> { pub struct IssueMut<'a, 'g> {
id: ObjectId, id: ObjectId,
clock: LClock, clock: clock::Lamport,
issue: Issue, issue: Issue,
store: &'g mut Issues<'a>, store: &'g mut Issues<'a>,
} }
impl<'a, 'g> IssueMut<'a, 'g> { impl<'a, 'g> IssueMut<'a, 'g> {
/// Get the internal logical clock. /// Get the internal logical clock.
pub fn clock(&self) -> &LClock { pub fn clock(&self) -> &clock::Lamport {
&self.clock &self.clock
} }
@ -372,7 +373,7 @@ impl<'a> Issues<'a> {
let change = Change { let change = Change {
author: self.author().id, author: self.author().id,
action: Action::Title { title }, action: Action::Title { title },
clock: LClock::default(), clock: clock::Lamport::default(),
}; };
let (id, issue): (_, Issue) = self.raw.create("Create issue", change, signer)?; let (id, issue): (_, Issue) = self.raw.create("Create issue", change, signer)?;
let mut issue = IssueMut { let mut issue = IssueMut {
@ -485,7 +486,7 @@ mod test {
.create("My first issue", "Blah blah blah.", &[], &signer) .create("My first issue", "Blah blah blah.", &[], &signer)
.unwrap(); .unwrap();
let comment = (LClock::default(), *signer.public_key()); let comment = (clock::Lamport::default(), *signer.public_key());
let reaction = Reaction::new('🥳').unwrap(); let reaction = Reaction::new('🥳').unwrap();
issue.react(comment, reaction, &signer).unwrap(); issue.react(comment, reaction, &signer).unwrap();

View File

@ -12,7 +12,7 @@ use crate::cob::store;
use crate::cob::{History, TypeName}; use crate::cob::{History, TypeName};
use crate::crypto::Signer; use crate::crypto::Signer;
use crdt::clock::LClock; use crdt::clock::Lamport;
use crdt::lwwreg::LWWReg; use crdt::lwwreg::LWWReg;
use crdt::lwwset::LWWSet; use crdt::lwwset::LWWSet;
use crdt::redactable::Redactable; use crdt::redactable::Redactable;
@ -72,9 +72,9 @@ pub struct Thread {
/// The comments under the thread. /// The comments under the thread.
comments: BTreeMap<CommentId, Redactable<Comment>>, comments: BTreeMap<CommentId, Redactable<Comment>>,
/// Associated tags. /// Associated tags.
tags: BTreeMap<Tag, LWWReg<bool, LClock>>, tags: BTreeMap<Tag, LWWReg<bool, Lamport>>,
/// Reactions to changes. /// Reactions to changes.
reactions: BTreeMap<CommentId, LWWSet<(ActorId, Reaction), LClock>>, reactions: BTreeMap<CommentId, LWWSet<(ActorId, Reaction), Lamport>>,
} }
impl store::FromHistory for Thread { impl store::FromHistory for Thread {
@ -380,7 +380,7 @@ mod tests {
let mut changes = Vec::new(); let mut changes = Vec::new();
let mut permutations: [Vec<Change<Action>>; N] = array::from_fn(|_| Vec::new()); let mut permutations: [Vec<Change<Action>>; N] = array::from_fn(|_| Vec::new());
let mut clock = LClock::default(); let mut clock = Lamport::default();
let author = ActorId::from([0; 32]); let author = ActorId::from([0; 32]);
for action in gen.take(g.size().min(8)) { for action in gen.take(g.size().min(8)) {