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

View File

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

View File

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

View File

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

View File

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