Skip to main content

VectorClock

Struct VectorClock 

Source
pub struct VectorClock {
    pub clocks: HashMap<ClientID, u64>,
}
Expand description

Vector clock for tracking causality between operations

Fields§

§clocks: HashMap<ClientID, u64>

Map from ClientID to logical clock value

Implementations§

Source§

impl VectorClock

Source

pub fn new() -> Self

Create a new empty vector clock

Source

pub fn from_timestamp(timestamp: &Timestamp) -> Self

Create a VectorClock from a Timestamp

Source

pub fn tick(&mut self, client_id: &ClientID)

Increment the clock for a specific client

Source

pub fn get(&self, client_id: &ClientID) -> u64

Get the clock value for a specific client

Source

pub fn update(&mut self, client_id: &ClientID, value: u64)

Update the clock for a specific client to a specific value

Source

pub fn clocks(&self) -> &HashMap<ClientID, u64>

Get all client clocks

Source

pub fn merge(&mut self, other: &VectorClock)

Merge with another vector clock (take max of each entry)

This operation is used when receiving remote operations. It ensures that all causal dependencies are tracked.

Source

pub fn compare(&self, other: &VectorClock) -> Ordering

Compare two vector clocks to determine happens-before relationship

Returns:

  • Ordering::Less: self happened before other (self < other)
  • Ordering::Greater: other happened before self (self > other)
  • Ordering::Equal: clocks are identical (rare in distributed systems)

Note: This function returns Equal for concurrent events where neither happened before the other. Use is_concurrent to explicitly check.

Source

pub fn is_concurrent(&self, other: &VectorClock) -> bool

Check if two vector clocks are concurrent (neither happened before the other)

Source

pub fn happened_before(&self, other: &VectorClock) -> bool

Check if self happened before other (self < other)

Trait Implementations§

Source§

impl Clone for VectorClock

Source§

fn clone(&self) -> VectorClock

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for VectorClock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VectorClock

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for VectorClock

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for VectorClock

Source§

fn eq(&self, other: &VectorClock) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for VectorClock

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for VectorClock

Source§

impl StructuralPartialEq for VectorClock

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,