RGAList

Struct RGAList 

Source
pub struct RGAList<T: Clone + PartialEq> {
    nodes: HashMap<ListId, ListNode<T>>,
    children: HashMap<ListId, Vec<ListId>>,
    replica_id: String,
    seq: u64,
    pending_delta: Option<RGAListDelta<T>>,
}
Expand description

Replicated Growable Array - an ordered list CRDT.

Supports insert, delete, and move operations with deterministic conflict resolution.

Fields§

§nodes: HashMap<ListId, ListNode<T>>

All nodes indexed by their ID.

§children: HashMap<ListId, Vec<ListId>>

Children of each node (for ordering). Maps origin -> list of children sorted by ID.

§replica_id: String

The replica ID for this instance.

§seq: u64

Sequence counter for generating IDs.

§pending_delta: Option<RGAListDelta<T>>

Pending delta for replication.

Implementations§

Source§

impl<T: Clone + PartialEq> RGAList<T>

Source

pub fn new(replica_id: impl Into<String>) -> Self

Create a new empty RGA list.

Source

pub fn replica_id(&self) -> &str

Get the replica ID.

Source

fn next_id(&mut self) -> ListId

Generate a new unique ID.

Source

pub fn insert(&mut self, index: usize, value: T)

Insert a value at the given index.

Source

pub fn insert_after(&mut self, origin: &ListId, value: T)

Insert a value after the given origin ID.

Source

pub fn push_front(&mut self, value: T)

Insert at the beginning.

Source

pub fn push_back(&mut self, value: T)

Insert at the end.

Source

pub fn delete(&mut self, index: usize) -> Option<T>

Delete the element at the given index.

Source

pub fn delete_by_id(&mut self, id: &ListId) -> Option<T>

Delete an element by its ID.

Source

pub fn move_element(&mut self, from: usize, to: usize) -> bool

Move an element from one index to another.

Source

pub fn get(&self, index: usize) -> Option<&T>

Get the element at the given index.

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>

Get a mutable reference to the element at the given index.

Source

pub fn len(&self) -> usize

Get the number of non-deleted elements.

Source

pub fn is_empty(&self) -> bool

Check if the list is empty.

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Iterate over values in order.

Source

pub fn iter_indexed(&self) -> impl Iterator<Item = (usize, &T)>

Iterate over (index, value) pairs.

Source

pub fn to_vec(&self) -> Vec<T>

Convert to a Vec.

Source

fn id_at_index(&self, index: usize) -> Option<ListId>

Get the ID at a given visible index.

Source

pub fn index_of_id(&self, id: &ListId) -> Option<usize>

Get the visible index for an ID.

Source

fn iter_nodes(&self) -> impl Iterator<Item = &ListNode<T>>

Iterate over all nodes in order (including tombstones).

Source

fn integrate_node(&mut self, node: ListNode<T>)

Integrate a node into the list.

Source

pub fn take_delta(&mut self) -> Option<RGAListDelta<T>>

Take the pending delta.

Source

pub fn apply_delta(&mut self, delta: &RGAListDelta<T>)

Apply a delta from another replica.

Trait Implementations§

Source§

impl<T: Clone + Clone + PartialEq> Clone for RGAList<T>

Source§

fn clone(&self) -> RGAList<T>

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<T: Debug + Clone + PartialEq> Debug for RGAList<T>

Source§

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

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

impl<T: Clone + PartialEq> Default for RGAList<T>

Source§

fn default() -> Self

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

impl<'de, T> Deserialize<'de> for RGAList<T>
where T: Deserialize<'de> + Default + Clone + PartialEq,

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<T: Clone + PartialEq> Lattice for RGAList<T>

Source§

fn bottom() -> Self

The bottom element (identity for join)
Source§

fn join(&self, other: &Self) -> Self

Join operation (least upper bound) Must be commutative, associative, and idempotent
Source§

fn partial_cmp_lattice(&self, other: &Self) -> Option<Ordering>

Partial order derived from join: a ≤ b iff a ⊔ b = b
Source§

fn leq(&self, other: &Self) -> bool

Check if self ≤ other in the lattice order
Source§

fn join_assign(&mut self, other: &Self)

Join-assign: self = self ⊔ other
Source§

impl<T: Clone + PartialEq> PartialEq for RGAList<T>

Source§

fn eq(&self, other: &Self) -> 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<T> Serialize for RGAList<T>
where T: Serialize + Clone + PartialEq,

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

Auto Trait Implementations§

§

impl<T> Freeze for RGAList<T>

§

impl<T> RefUnwindSafe for RGAList<T>
where T: RefUnwindSafe,

§

impl<T> Send for RGAList<T>
where T: Send,

§

impl<T> Sync for RGAList<T>
where T: Sync,

§

impl<T> Unpin for RGAList<T>
where T: Unpin,

§

impl<T> UnwindSafe for RGAList<T>
where T: UnwindSafe,

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> 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,