Rga
testedReplicated Growable Array — a sequence CRDT. Each element is inserted after a
left-origin element (or at the start) and tombstoned on delete. Concurrent
inserts at the same origin are ordered higher-op-id-first, a deterministic
tie-break that makes every replica converge to the same order. Operations must
be integrated in causal order (an insert's origin must already be present);
integrateInsert returns false when the origin is missing so the
caller can buffer and retry.
Signature
class Rga<T>Type Parameters
TProperties
| Property | Type | Description |
|---|---|---|
lengthreadonly | number | Number of visible elements. |
Methods
hashas(id: OpId): boolean| Parameter | Type | Description |
|---|---|---|
id | OpId | — |
booleanintegrateInsertIntegrate an insert after originLeft (null = start). Idempotent.
integrateInsert(id: OpId, value: T, originLeft: OpId | null): boolean| Parameter | Type | Description |
|---|---|---|
id | OpId | — |
value | T | — |
originLeft | OpId | null | — |
booleanintegrateDeleteTombstone an element. Idempotent; returns false if the element is unknown.
integrateDelete(id: OpId): boolean| Parameter | Type | Description |
|---|---|---|
id | OpId | — |
booleangcDrop tombstoned nodes whose insert is covered by stable. Call ONLY at
quiescence — when every replica has fully synced and no operations are in
flight — otherwise a late op that uses a dropped node as its origin can no
longer integrate. keep protects ids still referenced elsewhere (e.g. mark
span endpoints). Returns the number of nodes removed.
gc(stable: VersionVector, keep?: (id: OpId) => boolean): number| Parameter | Type | Description |
|---|---|---|
stable | VersionVector | — |
keep? | (id: OpId) => boolean | — |
numbertoArrayVisible values in document order.
toArray(): T[]T[]visibleVisible nodes in document order (read ids for cursor anchoring).
visible(): Array<RgaNode<T>>Array<RgaNode<T>>allAll nodes including tombstones (for state encoding).
all(): ReadonlyArray<RgaNode<T>>ReadonlyArray<RgaNode<T>>idAtOp id of the visible element at index, or null if out of range.
idAt(index: number): OpId | null| Parameter | Type | Description |
|---|---|---|
index | number | — |
OpId | null