code wiki / (root) / nx_crdt_seq.nx

nx_crdt_seq.nx

buildroot/runtime/nx_crdt_seq.nx

4377 B106 linesdepth 2pulls 2 transitivereach 3 importersview sourcekind librarytopic crdt
docsdependenciesstructsconstsfunctions

about

nx_crdt_seq.nx -- SOVEREIGN SEQUENCE CRDT (RGA: Replicated Growable Array, Roh et al. 2011). The V-COLLAB rung-1 fix for the recurring multi-agent EDIT COLLISION (two Claude sessions "file modified since read" = the git/gitea collision the operator asked to KILL 2026-05-27). Each element has a unique id (lamport clock, actor) + the id of the element it was inserted AFTER (its RGA reference/parent). Concurrent inserts after the same reference are ordered by a DETERMINISTIC total order on ids (descending) that every replica computes identically -> ALL replicas converge to the SAME sequence regardless of op arrival order, and NO concurrent edit is ever lost (unlike a lock/ last-writer-wins, which drops one). 100% integer, deterministic. license_tier: ORIGINAL

dependencies 1 imports · 3 importers

nx_syscalls.nx nx_crdt_seq.nx nx_crdt_seq_gate.nx nx_crdt_sync.nx nx_crdt_sync_gate.nx

imports: nx_syscalls.nx

imported by: nx_crdt_seq_gate.nxnx_crdt_sync.nxnx_crdt_sync_gate.nx

structs

none

consts

10const SEQ_MAX: i64 = 512 // max elements
11const SEQ_INF: i64 = 1000000000 // id-ceiling sentinel (> any real clock)

functions

14func seq_item(doc: *i64, i: i64) -> *i64 { return (doc as i64 + (1 + i*6)*8) as *i64 }
16func seq_new() -> *i64
called by 2: mainmain calls 1: sys_mmap
21func seq_count(doc: *i64) -> i64 { return doc[0] }
24func id_lt(ac: i64, aa: i64, bc: i64, ba: i64) -> i64
called by 1: seq_emit_children
31func seq_find(doc: *i64, idc: i64, ida: i64) -> i64
called by 2: seq_addseq_delete calls 1: seq_item
44func seq_add(doc: *i64, idc: i64, ida: i64, value: i64, refc: i64, refa: i64) -> i64
56func seq_delete(doc: *i64, idc: i64, ida: i64) -> i64
64func seq_emit_children(doc: *i64, refc: i64, refa: i64, out: *u8, olen: *i64, prevc: i64, preva: i64) -> i64
101func seq_materialize(doc: *i64, out: *u8) -> i64
called by 2: mainmain calls 2: sys_mmapseq_emit_children