RgaList<T> class
A Replicated Growable Array (RGA) — a convergent ordered-sequence CRDT.
This is the sequence type collaborative editors need: concurrent inserts and
deletes on different devices merge deterministically without dropping
elements. Each element is identified by (replicaId, counter) and anchored
after the element it was inserted behind; concurrent inserts at the same
anchor are ordered by Lamport counter (newest first), so every replica
arrives at the same order from the same element set.
Like the other CRDTs in this file it is immutable — operations return a new list — and merging is a state-based union (commutative, associative, idempotent):
var a = RgaList<String>(replicaId: 'device-a').insertAll(0, ['h', 'i']);
var b = RgaList<String>.fromMap(a.toMap(), (v) => v as String, replicaId: 'device-b');
a = a.insert(2, '!'); // device A appends '!'
b = b.insert(0, '>'); // device B prepends '>'
final mergedA = a.merge(b);
final mergedB = b.merge(a);
assert(mergedA.value.join() == mergedB.value.join()); // '>hi!'
Contiguous runs inserted with insertAll (or RgaText.insert) chain each element to the previous one, so two devices typing words concurrently at the same spot do not interleave characters.
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
-
idsInOrder
→ List<
String> -
The visible element ids in order — stable handles for cursor positions.
no setter
- isEmpty → bool
-
Whether the sequence has no visible elements.
no setter
- length → int
-
Number of visible elements.
no setter
-
props
→ List<
Object?> -
The list of properties that will be used to determine whether
two instances are equal.
no setter
- replicaId → String
-
This replica's identity, stamped on locally created elements.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stringify → bool?
-
If set to
true, thetoStringmethod will be overridden to output this instance'sprops.no setterinherited - tombstoneCount → int
-
Number of tombstoned elements retained for ordering (see compacted).
no setter
-
value
→ List<
T> -
The visible (non-tombstoned) elements, in convergent order.
no setteroverride
Methods
-
add(
T element) → RgaList< T> -
Appends
elementat the end of the sequence. -
compacted(
) → RgaList< T> - Returns a copy with every tombstone purged.
-
elementIdAt(
int index) → String -
The id of the visible element at
index. -
indexOfId(
String id) → int -
The visible index of element
id, or -1 if absent/tombstoned. -
insert(
int index, T element) → RgaList< T> -
Inserts
elementat visibleindex(0 = head, length = append). -
insertAll(
int index, Iterable< T> elements) → RgaList<T> -
Inserts
elementsas a contiguous run at visibleindex. -
merge(
covariant RgaList< T> other) → RgaList<T> -
Merges this CRDT with another of the same type.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
removeAt(
int index) → RgaList< T> -
Tombstones the visible element at
index. -
removeById(
String id) → RgaList< T> -
Tombstones the element with
id(no-op if unknown). -
removeRange(
int index, int count) → RgaList< T> -
Tombstones
countvisible elements starting atindex. -
toMap(
) → Map< String, dynamic> -
Converts the CRDT state to a map for serialization.
override
-
toString(
) → String - A string representation of this object.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited