code wiki / _hdl_build / nx_viz_datajoin.nx

nx_viz_datajoin.nx source

↩ module page · 25 lines · 1206 B

1// nx_viz_datajoin.nx -- the DATA-JOIN math core of the INTERACTION layer (the d3-selection enter/update/exit 2// core, bits-up). Given the currently-bound keys (old) and the new data keys, classify each new key as UPDATE 3// (key already present) or ENTER (new), and count EXITs (old keys gone). The set-diff that drives every d3 4// data-join. Pure integer -> WASM-deployable. Closes sel-datajoin. license_tier: ORIGINAL 5import "nx_syscalls.nx" 6 7// class_out[i] for new key i: 1=update (in old), 0=enter (new). returns exit count (old keys not in new). 8func vj_classify(new_keys: *i64, n_new: i64, old_keys: *i64, n_old: i64, class_out: *i64) -> i64 { 9 var i: i64 = 0 10 while i < n_new { 11 var found: i64 = 0; var j: i64 = 0 12 while j < n_old { if old_keys[j] == new_keys[i] { found = 1; j = n_old } else { j = j + 1 } } 13 class_out[i] = found 14 i = i + 1 15 } 16 var exits: i64 = 0; var k: i64 = 0 17 while k < n_old { 18 var f2: i64 = 0; var m: i64 = 0 19 while m < n_new { if new_keys[m] == old_keys[k] { f2 = 1; m = n_new } else { m = m + 1 } } 20 if f2 == 0 { exits = exits + 1 } 21 k = k + 1 22 } 23 return exits 24} 25func main() -> i64 { return 0 }