VersionVector

Struct VersionVector 

Source
pub struct VersionVector {
    entries: BTreeMap<String, u64>,
}
Expand description

A version vector tracking the frontier of seen updates per replica.

Version vectors provide a compact summary of causal history when updates from each replica are contiguous (no gaps).

Fields§

§entries: BTreeMap<String, u64>

Map from replica ID to highest seen sequence number.

Implementations§

Source§

impl VersionVector

Source

pub fn new() -> Self

Create an empty version vector.

Source

pub fn from_entries(entries: impl IntoIterator<Item = (String, u64)>) -> Self

Create a version vector from entries.

Source

pub fn get(&self, replica_id: &str) -> u64

Get the sequence number for a replica.

Source

pub fn set(&mut self, replica_id: impl Into<String>, sequence: u64)

Set the sequence number for a replica.

Source

pub fn increment(&mut self, replica_id: impl Into<String>) -> u64

Increment the sequence number for a replica, returning the new value.

Source

pub fn dominates(&self, other: &VersionVector) -> bool

Check if this vector dominates another (is causally after or concurrent). Returns true if for all replicas, self[r] >= other[r].

Source

pub fn strictly_dominates(&self, other: &VersionVector) -> bool

Check if this vector is strictly greater than another. Returns true if dominates(other) AND self != other.

Source

pub fn is_concurrent_with(&self, other: &VersionVector) -> bool

Check if two vectors are concurrent (neither dominates the other).

Source

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

Merge with another version vector (component-wise max).

Source

pub fn merged_with(&self, other: &VersionVector) -> VersionVector

Create a merged version vector without modifying self.

Source

pub fn min_with(&self, other: &VersionVector) -> VersionVector

Get the minimum across all replicas in both vectors. This represents the “stable” point that all replicas have seen.

Source

pub fn iter(&self) -> impl Iterator<Item = (&String, &u64)>

Iterate over all entries.

Source

pub fn len(&self) -> usize

Get the number of replicas tracked.

Source

pub fn is_empty(&self) -> bool

Check if the version vector is empty.

Source

pub fn total_operations(&self) -> u64

Get the sum of all sequence numbers (total operations seen).

Source

pub fn to_entries(&self) -> Vec<VectorEntry>

Convert to a list of entries.

Source

pub fn from_entry_list(entries: Vec<VectorEntry>) -> Self

Create from a list of entries.

Source

pub fn contains(&self, replica_id: &str, sequence: u64) -> bool

Check if a specific (replica_id, sequence) pair is included.

Source

pub fn diff(&self, other: &VersionVector) -> Vec<(String, u64, u64)>

Get the difference: operations in self but not in other. Returns (replica_id, start_seq, end_seq) ranges.

Trait Implementations§

Source§

impl Clone for VersionVector

Source§

fn clone(&self) -> VersionVector

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 VersionVector

Source§

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

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

impl Default for VersionVector

Source§

fn default() -> VersionVector

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

impl<'de> Deserialize<'de> for VersionVector

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 VersionVector

Source§

fn eq(&self, other: &VersionVector) -> 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 VersionVector

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 VersionVector

Source§

impl StructuralPartialEq for VersionVector

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> Same for T

Source§

type Output = T

Should always be Self
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>,