RGA suits well for keeping any ordered collection.
For example, strings may be expressed as an RGA of characters (codepoints, actually).
RON text:
rga
Hexadecimal:
0x 0dab 9400 0000 0000
0000 0000 0000 0000
- Insert:
- ref is the parent vertex id.
- 0 is the special "invisible root" vertex.
- payload is the value.
- ref is the parent vertex id.
- Remove:
- ref is the target vertex id.
- payload is empty.
-
Replica
alfa
creates an RGA from string"hi"
at time 27, inserting each character after previous one:*rga #27+alfa @27+alfa :0 'h' ; *rga #27+alfa @2700000001+alfa :27+alfa 'i' ;
with compression:
*rga #27+alfa @` 'h' ; @)1 :) 'i' ;
-
Replica
bravo
capitalizes first letter by removing@27+alfa 'h'
and inserting'H'
in the root.*rga #27+alfa @42+bravo :27+alfa ; *rga #27+alfa @4200000001+bravo :0 'H' ;
with compression:
*rga #27+alfa @42+bravo :27+alfa ; @)1 :0 'H' ;
- Chunk version is calculated as the maximum event or ref of contained ops.
- Reduced op format:
- event is the vertex id
- Alive vertex (vertex that has not been removed) 2. ref is 0 3. payload is the value
- Tombstone (removed vertex) 2. ref is the event of the last removal op 3. payload is the value, for the purpose of undo
- The order of ops is specified in RGA definition.
-
Empty RGA
*rga #71+charlie @71+charlie :0 !
-
Replica
alfa
creates an RGA from string"hi"
at time 27, inserting each character after previous one:*rga #27+alfa @27+alfa :0 ! *rga #27+alfa @27+alfa :0 'h' , *rga #27+alfa @2700000001+alfa :0 'i' ,
with compression:
*rga #27+alfa @` ! 'h' , @)1 'i' ,
-
Replica
bravo
capitalizes first letter by removing@27+alfa 'h'
and inserting'H'
in the root.*rga #27+alfa @27+alfa :0 ! *rga #27+alfa @4200000001+bravo :0 'H' , *rga #27+alfa @27+alfa :42+bravo 'h' , *rga #27+alfa @2700000001+alfa :0 'i' ,
with compression:
*rga #27+alfa @27+alfa ! @4200000001+bravo 'H' , @` :42+bravo 'h' , @)1 :0 'i' ,
- The same as the value representation. Hence, a patch is a sub-array.
- The chunk ref is the parent vertex id.
- For each vertex in a value or patch there must be exactly one op with corresponding event.
- Removal has precedence over addition. For the same vertex, the op with the maximum ref is chosen.
- Insertion and value reduction is specified by the RGA definition.
- Since patched are RGAs, too, patches are reduced by the same algorithm, if applicable.