pub struct Clock {
lamport_clock: i64,
vector_clock: HashMap<String, i64>,
}
Expand description
Implements logical clocks for distributed synchronization
The Clock struct maintains both a Lamport clock for total ordering and a vector clock for causal ordering of events across the distributed system.
Fields§
§lamport_clock: i64
Lamport clock value for total ordering of events
vector_clock: HashMap<String, i64>
Vector clock mapping site IDs to their clock values
Site_id -> clock value
Implementations§
Source§impl Clock
impl Clock
pub fn from_parts( lamport_clock: i64, vector_clock: HashMap<String, i64>, ) -> Self
Sourcefn increment_lamport(&mut self)
fn increment_lamport(&mut self)
Increments the Lamport clock and returns the new value
Sourcefn increment_vector(&mut self, site_id: &str)
fn increment_vector(&mut self, site_id: &str)
Increments the vector clock for a specific site and returns the new value
Sourcepub fn get_lamport(&self) -> &i64
pub fn get_lamport(&self) -> &i64
Returns a reference to the Lamport clock value
Sourcepub fn get_vector_clock_map(&self) -> &HashMap<String, i64>
pub fn get_vector_clock_map(&self) -> &HashMap<String, i64>
Returns a reference to the vector clock
Sourcepub fn get_vector_clock_values(&self) -> Vec<i64>
pub fn get_vector_clock_values(&self) -> Vec<i64>
Returns the vector clock as a list of values
Sourcefn update_vector(&mut self, received_vc: &HashMap<String, i64>)
fn update_vector(&mut self, received_vc: &HashMap<String, i64>)
Updates the vector clock with received values, taking the maximum of local and received values
Sourcefn update_lamport(&mut self, received_lc: &i64)
fn update_lamport(&mut self, received_lc: &i64)
Updates the lamport clock with received value, taking the maximum of local and received values
Sourcepub fn update_clock(
&mut self,
local_site_id: &str,
received_clock: Option<&Self>,
)
pub fn update_clock( &mut self, local_site_id: &str, received_clock: Option<&Self>, )
Update the current clock value with an optional clock
Local lamport clock is incremented
Element of local vector clock is incremented
Then we call update methods to take the maximum of the received clocks if any