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
impl VectorClock
Sourcepub fn from_timestamp(timestamp: &Timestamp) -> Self
pub fn from_timestamp(timestamp: &Timestamp) -> Self
Create a VectorClock from a Timestamp
Sourcepub fn update(&mut self, client_id: &ClientID, value: u64)
pub fn update(&mut self, client_id: &ClientID, value: u64)
Update the clock for a specific client to a specific value
Sourcepub fn merge(&mut self, other: &VectorClock)
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.
Sourcepub fn compare(&self, other: &VectorClock) -> Ordering
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.
Sourcepub fn is_concurrent(&self, other: &VectorClock) -> bool
pub fn is_concurrent(&self, other: &VectorClock) -> bool
Check if two vector clocks are concurrent (neither happened before the other)
Sourcepub fn happened_before(&self, other: &VectorClock) -> bool
pub fn happened_before(&self, other: &VectorClock) -> bool
Check if self happened before other (self < other)
Trait Implementations§
Source§impl Clone for VectorClock
impl Clone for VectorClock
Source§fn clone(&self) -> VectorClock
fn clone(&self) -> VectorClock
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for VectorClock
impl Debug for VectorClock
Source§impl Default for VectorClock
impl Default for VectorClock
Source§impl<'de> Deserialize<'de> for VectorClock
impl<'de> Deserialize<'de> for VectorClock
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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
impl PartialEq for VectorClock
Source§impl Serialize for VectorClock
impl Serialize for VectorClock
impl Eq for VectorClock
impl StructuralPartialEq for VectorClock
Auto Trait Implementations§
impl Freeze for VectorClock
impl RefUnwindSafe for VectorClock
impl Send for VectorClock
impl Sync for VectorClock
impl Unpin for VectorClock
impl UnwindSafe for VectorClock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more