https://github.com/veminovici/euklid
A rust library for distributed causality, dot, version-vector, dotted-version-vector, CDR types: g-counter
https://github.com/veminovici/euklid
causality clock crdt distr dotted-vector-clocks dotted-version-vector gcounter replicas
Last synced: 5 months ago
JSON representation
A rust library for distributed causality, dot, version-vector, dotted-version-vector, CDR types: g-counter
- Host: GitHub
- URL: https://github.com/veminovici/euklid
- Owner: veminovici
- Created: 2021-09-07T20:09:56.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2022-03-18T08:45:36.000Z (about 4 years ago)
- Last Synced: 2025-08-26T04:38:44.124Z (10 months ago)
- Topics: causality, clock, crdt, distr, dotted-vector-clocks, dotted-version-vector, gcounter, replicas
- Language: Rust
- Homepage:
- Size: 187 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#  Simplee...Euklid...
Just another rust crate, this one implements CRDTs things.
[](https://github.com/veminovici/euklid/actions/workflows/ci.yml)
[](https://github.com/veminovici/euklid)
[](https://github.com/veminovici/euklid)
[](https://github.com/veminovici/euklid)
## 1. Causality
### 1.1. Causality Enumeration
The crate defines the **CausalOrdering** enumeration which has 4 values:
```rust
pub enum Causality {
/// An event precedes another event.
Precede,
/// An event is equal with another event.
Equal,
/// An event succeeds another event.
Succeed,
/// An event is concurrent with another event.
Concurrent,
}
```
### 1.2. CausalityOrd Trait
The crate also defines **CausalOrd** trait which along with the **CasualOrdering** allows the caller
to determine if there is any causality between two different instances of the **CausalOrd**.
```rust
/// A trait that compares two events and returns their causality relation.
pub trait CausalityOrd: PartialOrd {
/// Returns the causality relation between two entities.
fn causality_cmp(&self, other: &Self) -> Causality {
match self.partial_cmp(other) {
Some(core::cmp::Ordering::Equal) => Causality::Equal,
Some(core::cmp::Ordering::Less) => Causality::Precede,
Some(core::cmp::Ordering::Greater) => Causality::Succeed,
None => Causality::Concurrent,
}
}
}
```
## 2. Identities, Actors, and Counters Traits
### 2.1. Identities
These are traits that define the *zero* and *one* values for a type.
```rust
/// Represents the identity value `zero`.
pub trait Zero {
/// Returns the `zero` value for the type.
fn zero() -> Self;
}
/// represents the identity value `one`.
pub trait One {
/// Returns the `one` value for the type.
fn one() -> Self;
}
```
### 2.2. Actors and Counters
The *Actor* trait defines the expected traits for an actor identifies. The *Counter* trait defines the expected traits for a counter.
```rust
pub trait Actor: Copy + Ord + Zero {}
pub trait Counter: Copy + PartialOrd + Add + AddAssign + Sub + SubAssign + Zero + One {}
```
The crate implements the *Actor* and *Counter* traits for all basic numeric types: *usize*, *u8*, *u16*, ..., *i8*, *i16*, ...
## 3. CvRDT and CmRDT Traits
### 3.1. CvRDT Trait
The *CvRDT* trait defines the converging or state based merge synchronization.
```rust
pub trait CvRDT {
/// Merge the given CRDT into the current CRDT.
fn merge(&mut self, other: Self);
}
```
### 3.2. CmRDT Trait
The *CmRDT* trait defines the commuting or operation based synchronization.
```rust
pub trait CmRDT {
/// Op's must be idempotent, meaning any Op may be applied more than once.
type Op;
/// Apply an Op to the CRDT
fn apply(&mut self, op: Self::Op);
}
```
## 4. CRDTs
### 4.1. Dot
### 4.2. VClock
### 4.3. GCounter
### 4.4. PNCounter