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.
§Example
use crdt_kit::prelude::*;
let mut list1 = Rga::new(1);
list1.insert_at(0, 'H').unwrap();
list1.insert_at(1, 'i').unwrap();
let mut list2 = Rga::new(2);
list2.insert_at(0, '!').unwrap();
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 fork(&self, new_actor: NodeId) -> Self
pub fn fork(&self, new_actor: NodeId) -> Self
Create a fork of this replica with a different node ID.
Sourcepub fn insert_at(&mut self, index: usize, value: T) -> Result<(), RgaError>
pub fn insert_at(&mut self, index: usize, value: T) -> Result<(), RgaError>
Insert a value at the given index in the visible sequence.
Sourcepub fn remove(&mut self, index: usize) -> Result<T, RgaError>
pub fn remove(&mut self, index: usize) -> Result<T, RgaError>
Remove the element at the given index from the visible sequence.
Sourcepub fn get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Get a reference to the element at the given index in the visible sequence.
Trait Implementations§
Source§impl<T: Clone + Ord> DeltaCrdt for Rga<T>
impl<T: Clone + Ord> DeltaCrdt for Rga<T>
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>where
T: Unpin,
impl<T> UnsafeUnpin for Rga<T>
impl<T> UnwindSafe for Rga<T>where
T: UnwindSafe,
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