Struct yrs::StateVector
source · pub struct StateVector(/* private fields */);
Expand description
State vector is a compact representation of all known blocks inserted and integrated into a given document. This descriptor can be serialized and used to determine a difference between seen and unseen inserts of two replicas of the same document, potentially existing in different processes.
Another popular name for the concept represented by state vector is Version Vector.
Implementations§
source§impl StateVector
impl StateVector
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns a number of unique clients observed by a document, current state vector corresponds to.
pub fn new( map: HashMap<ClientID, u32, BuildHasherDefault<ClientHasher>> ) -> Self
sourcepub fn contains(&self, id: &ID) -> bool
pub fn contains(&self, id: &ID) -> bool
Checks if current state vector includes given block identifier. Blocks, which identifiers can be found in a state vectors don’t need to be encoded as part of an update, because they were already observed by their remote peer, current state vector refers to.
pub fn contains_client(&self, client_id: &ClientID) -> bool
sourcepub fn get(&self, client_id: &ClientID) -> u32
pub fn get(&self, client_id: &ClientID) -> u32
Get the latest clock sequence number value for a given client_id
as observed from
the perspective of a current state vector.
sourcepub fn inc_by(&mut self, client: ClientID, delta: u32)
pub fn inc_by(&mut self, client: ClientID, delta: u32)
Updates a state vector observed clock sequence number for a given client
by incrementing
it by a given delta
.
sourcepub fn set_min(&mut self, client: ClientID, clock: u32)
pub fn set_min(&mut self, client: ClientID, clock: u32)
Updates a state vector observed clock sequence number for a given client
by setting it to
a minimum value between an already present one and the provided clock
. In case if state
vector didn’t contain any value for that client
, a clock
value will be used.
sourcepub fn set_max(&mut self, client: ClientID, clock: u32)
pub fn set_max(&mut self, client: ClientID, clock: u32)
Updates a state vector observed clock sequence number for a given client
by setting it to
a maximum value between an already present one and the provided clock
. In case if state
vector didn’t contain any value for that client
, a clock
value will be used.
sourcepub fn iter(&self) -> Iter<'_, ClientID, u32> ⓘ
pub fn iter(&self) -> Iter<'_, ClientID, u32> ⓘ
Returns an iterator which enables to traverse over all clients and their known clock values described by a current state vector.
sourcepub fn merge(&mut self, other: Self)
pub fn merge(&mut self, other: Self)
Merges another state vector into a current one. Since vector’s clock values can only be incremented, whenever a conflict between two states happen (both state vectors have different clock values for the same client entry), a highest of these to is considered to be the most up-to-date.
Trait Implementations§
source§impl Clone for StateVector
impl Clone for StateVector
source§fn clone(&self) -> StateVector
fn clone(&self) -> StateVector
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for StateVector
impl Debug for StateVector
source§impl Decode for StateVector
impl Decode for StateVector
source§impl Default for StateVector
impl Default for StateVector
source§fn default() -> StateVector
fn default() -> StateVector
source§impl Encode for StateVector
impl Encode for StateVector
source§impl PartialEq for StateVector
impl PartialEq for StateVector
source§fn eq(&self, other: &StateVector) -> bool
fn eq(&self, other: &StateVector) -> bool
self
and other
values to be equal, and is used
by ==
.