pub struct Rga<T: Clone + Ord> { /* private fields */ }Expand description
A Replicated Growable Array (RGA) — an ordered sequence CRDT.
RGA supports insert and delete at arbitrary positions while
guaranteeing convergence across replicas. Each element is assigned
a unique identifier (actor, counter) which determines causal
ordering. When two replicas concurrently insert at the same
position, the conflict is resolved deterministically by comparing
the unique identifiers, ensuring all replicas converge to the
same sequence after merging.
§Example
use crdt_kit::prelude::*;
let mut list1 = Rga::new("node-1");
list1.insert_at(0, 'H');
list1.insert_at(1, 'i');
let mut list2 = Rga::new("node-2");
list2.insert_at(0, '!');
list1.merge(&list2);
list2.merge(&list1);
// Both replicas converge to the same sequence
let v1: Vec<&char> = list1.iter().collect();
let v2: Vec<&char> = list2.iter().collect();
assert_eq!(v1, v2);
assert_eq!(list1.len(), 3);Implementations§
Source§impl<T: Clone + Ord> Rga<T>
impl<T: Clone + Ord> Rga<T>
Sourcepub fn remove(&mut self, index: usize) -> Option<T>
pub fn remove(&mut self, index: usize) -> Option<T>
Remove the element at the given index from the visible sequence.
Returns the removed value, or None if the index is out of bounds.
Trait Implementations§
impl<T: Eq + Clone + Ord> Eq for Rga<T>
impl<T: Clone + Ord> StructuralPartialEq for Rga<T>
Auto Trait Implementations§
impl<T> Freeze for Rga<T>
impl<T> RefUnwindSafe for Rga<T>where
T: RefUnwindSafe,
impl<T> Send for Rga<T>where
T: Send,
impl<T> Sync for Rga<T>where
T: Sync,
impl<T> Unpin for Rga<T>
impl<T> UnwindSafe for Rga<T>where
T: RefUnwindSafe,
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