nx_cdmap_lib.nx
buildroot/runtime/nx_cdmap_lib.nx
about
nx_cdmap_lib.nx -- THE ONE centrality/distinctiveness ruler for every /compare board (2026-09-15).
WHY. Operator, 2026-09-15 (the /goal): "a multi variable four quadrant visual thats emitted to properly show
where we are and our competitors and where we are moving as time goes on daily". The field's instrument is the
Centrality-Distinctiveness map (Dawar and Bagga, Harvard Business Review, June 2015, "A Better Way to Map Brand
Strategy"): X = how representative of its category a brand is, Y = how far it stands apart, the bubble a third
variable and its colour a fourth; the category's own averages cut four quadrants -- Aspirational (central AND
distinctive), Mainstream (central, undistinctive), Peripheral (neither), Unconventional (distinctive, uncentral).
Operator, same day: "extensible as we get more and more variables ... a 3 dimensional x y z axis cube with a 2d
cut and a 3d view". So the AXES ARE A REGISTRY (cd_axis_*), every axis reads on one permil scale, a board picks
any two as its 2D cut and any three as its cube through DATA (knowledge/compare/<dom>.cdmap), and the isometric
projection lives HERE so the gate can pin it. Adding a variable is one axis id, one name, one value rule.
HERE EVERY INPUT IS THE MATRIX THE BOARD ALREADY MEASURES. The map is a PROJECTION of the same cells the page
grades (Nishi's cell measured on disk, the rivals' cells documented presence), re-derived on every publish, so it
cannot say anything the cells do not; and the board's own history -- a per-domain day spine this lib writes once
per calendar day -- is the time axis, so "where we are moving" is a path on the page, never a claim.
THE ARITHMETIC (integer permil; nofloat; every constant named).
players P = Nishi + the @cols rivals. pts(p,r) = cd_pts(code): Best 3, Yes 2, Part 1, No 0 -- the scale the
page's pros/cons strip already uses (pc_pts). have(p,r) = pts > 0. hc(r) = players holding row r.
CENTRALITY(p) = 1000 * sum_r have(p,r)*hc(r) / sum_r hc(r)
the share of the category's feature mass the player covers, each feature weighted by how many hold it:
a player holding everything the field holds reads 1000; one holding only what nobody else has reads low.
DISTINCTIVENESS(p) = 1000 * sum_r lead(p,r) / (3 * (P-1) * sum_r have(p,r)),
lead(p,r) = sum over rivals q of max(0, pts(p,r) - pts(q,r)):
the average lead over each rival on the rows the player holds -- a Best where rivals hold Yes counts, a
feature no rival holds counts most, a player whose every feature is matched reads 0.
A player holding nothing reads 0 on both axes and quadrant ABSENT (never a division by zero).
BREADTH(p) = 1000 * sum_r pts(p,r) / (3 * rows) -- depth-weighted share of the whole matrix (the bubble).
DEPTH(p) = 1000 * sum_r pts(p,r) / (3 * held) -- how deeply the rows it holds are held (Best everywhere = 1000).
MOMENTUM(p) = (C_today - C_prev) + (D_today - D_prev) over the spine -- signed; unknown until day two; plotted as
(m + 1000) / 2 so a still player sits mid-axis.
The quadrant dividers are the MEANS over the players -- the category's own centre, as the map's authors draw it.
Ties: central iff C >= mean; distinctive iff D > mean (a field of identical players is Mainstream, never Aspirational).
THE SPINE. <dir><dom>.spine, one row per player per calendar day (UTC), appended by the FIRST publish of the day;
a re-publish the same day is a no-op by construction (the day column is the key):
cd|<epoch>|<day>|<player>|<centrality>|<distinctiveness>|<breadth-points>|<rows>|<players>|<held>
(held was appended 2026-09-15 for the depth axis; an older row without it reads held 0, never a crash.)
dependencies 1 imports · 3 importers
imports: nx_syscalls.nx
imported by: nx_cdmap_gate.nxnx_compare_feed_lib.nxnx_swcompare_lib.nx
structs
| none |
consts
| 47 | const CD_PTS_BEST: i64 = 3 |
| 48 | const CD_PTS_YES: i64 = 2 |
| 49 | const CD_PTS_PART: i64 = 1 |
| 50 | const CD_PTS_NO: i64 = 0 |
| 51 | const CD_CODE_NO: i64 = 0 |
| 52 | const CD_CODE_YES: i64 = 1 |
| 53 | const CD_CODE_BEST: i64 = 2 |
| 54 | const CD_CODE_PART: i64 = 3 |
| 55 | const CD_NISHI_ABSENT: i64 = 0 |
| 56 | const CD_NISHI_PRESENT: i64 = 1 |
| 57 | const CD_NISHI_EXCEED: i64 = 2 |
| 58 | const CD_PERMIL: i64 = 1000 |
| 59 | const CD_W: i64 = 4 // result words per player |
| 60 | const CD_R_C: i64 = 0 |
| 61 | const CD_R_D: i64 = 1 |
| 62 | const CD_R_BREADTH: i64 = 2 // raw depth-weighted points held |
| 63 | const CD_R_HELD: i64 = 3 |
| 64 | const CD_Q_ABSENT: i64 = 0 |
| 65 | const CD_Q_ASPIRATIONAL: i64 = 1 |
| 66 | const CD_Q_MAINSTREAM: i64 = 2 |
| 67 | const CD_Q_PERIPHERAL: i64 = 3 |
| 68 | const CD_Q_UNCONVENTIONAL: i64 = 4 |
| 69 | const CD_SECS_PER_DAY: i64 = 86400 |
| 70 | const CD_I64_BYTES: i64 = 8 |
| 71 | const CD_SPINE_DIR: *u8 = "knowledge/status/cdmap/" |
| 72 | const CD_SPINE_EXT: *u8 = ".spine" |
| 73 | const CD_SPINE_TAG: *u8 = "cd|" |
| 74 | const CD_SPINE_TAGLEN: i64 = 3 |
| 75 | const CD_SPINE_NF: i64 = 10 |
| 76 | const CD_F_TAG: i64 = 0 |
| 77 | const CD_F_EPOCH: i64 = 1 |
| 78 | const CD_F_DAY: i64 = 2 |
| 79 | const CD_F_PLAYER: i64 = 3 |
| 80 | const CD_F_C: i64 = 4 |
| 81 | const CD_F_D: i64 = 5 |
| 82 | const CD_F_BREADTH: i64 = 6 |
| 83 | const CD_F_ROWS: i64 = 7 |
| 84 | const CD_F_PLAYERS: i64 = 8 |
| 85 | const CD_F_HELD: i64 = 9 |
| 86 | const CD_PATH_CAP: i64 = 600 |
| 87 | const CD_ROW_CAP: i64 = 512 |
| 88 | const CD_NUM_SCRATCH: i64 = 32 |
| 89 | const CD_DIR_MODE: i64 = 493 // 0755 |
| 90 | const CD_FILE_MODE: i64 = 420 // 0644 |
| 91 | const CD_CH_PIPE: i64 = 124 |
| 92 | const CD_CH_LF: i64 = 10 |
| 93 | const CD_CH_CR: i64 = 13 |
| 94 | const CD_CH_HASH: i64 = 35 |
| 95 | const CD_CH_SPACE: i64 = 32 |
| 96 | const CD_CH_ZERO: i64 = 48 |
| 97 | const CD_CH_NINE: i64 = 57 |
| 98 | const CD_CH_MINUS: i64 = 45 |
| 99 | const CD_TEN: i64 = 10 |
| 101 | const CD_HIST_W: i64 = 14 |
| 102 | const CD_H_FC: i64 = 0 |
| 103 | const CD_H_FD: i64 = 1 |
| 104 | const CD_H_FDAY: i64 = 2 |
| 105 | const CD_H_PC: i64 = 3 |
| 106 | const CD_H_PD: i64 = 4 |
| 107 | const CD_H_PDAY: i64 = 5 |
| 108 | const CD_H_DAYS: i64 = 6 |
| 109 | const CD_H_LASTDAY: i64 = 7 |
| 110 | const CD_H_FB: i64 = 8 // first-day breadth points |
| 111 | const CD_H_FH: i64 = 9 // first-day held |
| 112 | const CD_H_FROWS: i64 = 10 // first-day matrix rows |
| 113 | const CD_H_PB: i64 = 11 // previous-day breadth points |
| 114 | const CD_H_PH: i64 = 12 // previous-day held |
| 115 | const CD_H_PROWS: i64 = 13 // previous-day matrix rows |
| 117 | const CD_AX_C: i64 = 0 |
| 118 | const CD_AX_D: i64 = 1 |
| 119 | const CD_AX_BREADTH: i64 = 2 |
| 120 | const CD_AX_DEPTH: i64 = 3 |
| 121 | const CD_AX_MOMENTUM: i64 = 4 |
| 122 | const CD_AX_N: i64 = 5 |
| 123 | const CD_AX_NONE: i64 = 0 - 1 |
| 124 | const CD_MOM_SPAN: i64 = 2000 // momentum ranges -1000..1000; plotted on 0..1000 |
| 125 | const CD_VIEW_CUT: i64 = 0 |
| 126 | const CD_VIEW_CUBE: i64 = 1 |
| 127 | const CD_CUT_AXES: i64 = 2 |
| 128 | const CD_CUBE_AXES: i64 = 3 |
| 129 | const CD_VIEW_DIR: *u8 = "knowledge/compare/" |
| 130 | const CD_VIEW_EXT: *u8 = ".cdmap" |
| 131 | const CD_VIEW_CUT_TAG: *u8 = "cut|" |
| 132 | const CD_VIEW_CUBE_TAG: *u8 = "cube|" |
| 133 | const CD_VIEW_ABSENT: i64 = 0 // no conf or no row for that view: the caller takes the default |
| 134 | const CD_VIEW_REFUSED: i64 = 0 - 1 // a row named an axis the registry does not have |
| 136 | const CD_ISO_COS_PERMIL: i64 = 866 |
| 137 | const CD_ISO_SIN_PERMIL: i64 = 500 |
| 139 | const CD_HIST_WHICH_FIRST: i64 = 0 |
| 140 | const CD_HIST_WHICH_PREV: i64 = 1 |
| 414 | const CD_NOTE_EXT: *u8 = ".cdnotes" |
| 415 | const CD_NOTE_TAG: *u8 = "note|" |
| 416 | const CD_NOTE_AT: *u8 = "at:" |
| 417 | const CD_NOTE_AT_LEN: i64 = 3 |
| 418 | const CD_NOTE_TEXT_MAX: i64 = 120 |
| 419 | const CD_NOTE_W: i64 = 12 |
| 420 | const CD_N_KIND: i64 = 0 |
| 421 | const CD_N_PLAYER: i64 = 1 |
| 422 | const CD_N_X: i64 = 2 |
| 423 | const CD_N_Y: i64 = 3 |
| 424 | const CD_N_TOFF: i64 = 4 |
| 425 | const CD_N_TLEN: i64 = 5 |
| 426 | const CD_N_IDOFF: i64 = 6 |
| 427 | const CD_N_IDLEN: i64 = 7 |
| 428 | const CD_N_SOFF: i64 = 8 |
| 429 | const CD_N_SLEN: i64 = 9 |
| 430 | const CD_N_BOFF: i64 = 10 |
| 431 | const CD_N_BLEN: i64 = 11 |
| 432 | const CD_NK_PLAYER: i64 = 1 |
| 433 | const CD_NK_AT: i64 = 2 |
| 434 | const CD_NF_ID: i64 = 1 |
| 435 | const CD_NF_ANCHOR: i64 = 2 |
| 436 | const CD_NF_TEXT: i64 = 3 |
| 437 | const CD_NF_SINCE: i64 = 4 |
| 438 | const CD_NF_BY: i64 = 5 |
| 439 | const CD_NS_ROWS: i64 = 0 // stats: rows tagged note| |
| 440 | const CD_NS_REFUSED: i64 = 1 // rows refused (counted, never rendered) |
| 441 | const CD_NS_W: i64 = 2 |
| 442 | const CD_CH_COMMA: i64 = 44 |
| 443 | const CD_NOTE_REFUSED: i64 = 0 - 1 |
| 778 | const CD_ROLE_SUBSTRATE: *u8 = "substrate" |
| 779 | const CD_ABSENT_PFX: *u8 = "_ABSENT_:" |
| 780 | const CD_ABSENT_PFX_LEN: i64 = 9 |
| 781 | const CD_RUNG_TAG: *u8 = "rung|" |
| 782 | const CD_RUNGROLE_TAG: *u8 = "rungrole|" |
| 783 | const CD_RUNG_F_ID: i64 = 1 |
| 784 | const CD_RUNG_F_SYM: i64 = 3 |
| 785 | const CD_ROLE_F_ID: i64 = 1 |
| 786 | const CD_ROLE_F_ROLE: i64 = 2 |
functions
| 142 | func cd_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 143 | func cd_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { d[o + i] = s[i]; i = i + 1 } return o + i } |
| 146 | func cd_cat_safe(d: *u8, o: i64, s: *u8) -> i64 called by 1: cd_spine_append |
| 157 | func cd_catn(d: *u8, o: i64, v: i64) -> i64 |
| 167 | func cd_signed(v: i64, neg: i64) -> i64 { if neg == 1 { return 0 - v } return v } called by 1: cd_atoi_n |
| 169 | func cd_atoi(s: *u8) -> i64 { return cd_atoi_n(s, cd_slen(s)) } |
| 171 | func cd_atoi_n(s: *u8, n: i64) -> i64 |
| 185 | func cd_isqrt(v: i64) -> i64 called by 1: main |
| 192 | func cd_clamp_permil(v: i64) -> i64 { if v < 0 { return 0 } if v > CD_PERMIL { return CD_PERMIL } return v } |
| 194 | func cd_pts(code: i64) -> i64 called by 1: main |
| 201 | func cd_nishi_pts(nishi: i64) -> i64 called by 1: main |
| 207 | func cd_compute(pts: *i64, np: i64, nr: i64, out: *i64) -> i64 |
| 252 | func cd_mean(out: *i64, np: i64, field: i64) -> i64 called by 1: main |
| 259 | func cd_quadrant(c: i64, d: i64, cmean: i64, dmean: i64, held: i64) -> i64 called by 1: main |
| 265 | func cd_quadrant_name(q: i64) -> *u8 |
| 273 | func cd_axis_name(id: i64) -> *u8 |
| 281 | func cd_name_eq_n(name: *u8, s: *u8, n: i64) -> i64 |
| 288 | func cd_axis_id(s: *u8, n: i64) -> i64 |
| 293 | func cd_breadth_permil(points: i64, rows: i64) -> i64 { if rows <= 0 { return 0 } return CD_PERMIL * points / (CD_PTS_BEST * rows) } |
| 294 | func cd_depth_permil(points: i64, held: i64) -> i64 { if held <= 0 { return 0 } return CD_PERMIL * points / (CD_PTS_BEST * held) } |
| 295 | func cd_momentum_known(hist: *i64) -> i64 { if hist[CD_H_PDAY] > 0 { return 1 } return 0 } called by 1: cd_momentum |
| 297 | func cd_momentum(out: *i64, p: i64, hist: *i64) -> i64 |
| 302 | func cd_mom_plot(m: i64) -> i64 { return cd_clamp_permil((m + CD_PERMIL) * CD_PERMIL / CD_MOM_SPAN) } |
| 304 | func cd_axis_value(out: *i64, p: i64, nr: i64, hist: *i64, id: i64) -> i64 |
| 313 | func cd_axis_plot(out: *i64, p: i64, nr: i64, hist: *i64, id: i64) -> i64 |
| 318 | func cd_hist_axis_plot(hist: *i64, which: i64, id: i64) -> i64 |
| 333 | func cd_axis_mean_plot(out: *i64, np: i64, nr: i64, hist: *i64, id: i64) -> i64 |
| 341 | func cd_view_default(view: i64, ids: *i64) -> i64 called by 1: main |
| 347 | func cd_view_axes(view: i64) -> i64 { if view == CD_VIEW_CUBE { return CD_CUBE_AXES } return CD_CUT_AXES } called by 1: cd_view_row |
| 348 | func cd_view_path(dir: *u8, dom: *u8, out: *u8) -> i64 |
| 356 | func cd_view_row(line: *u8, n: i64, view: i64, ids: *i64) -> i64 |
| 372 | func cd_row_tag_is(line: *u8, n: i64, tag: *u8) -> i64 |
| 381 | func cd_view_conf(dir: *u8, dom: *u8, view: i64, ids: *i64) -> i64 |
| 444 | func cd_notes_path(dir: *u8, dom: *u8, out: *u8) -> i64 |
| 451 | func cd_note_rec(recs: *i64, k: i64) -> *i64 { return (recs as i64 + k * CD_NOTE_W * CD_I64_BYTES) as *i64 } |
| 453 | func cd_notes_player(line: *u8, off: i64, len: i64, names: *i64, np: i64) -> i64 |
| 459 | func cd_note_at(line: *u8, off: i64, len: i64, xy: *i64) -> i64 |
| 475 | func cd_note_row(line: *u8, n: i64, base: i64, names: *i64, np: i64, rec: *i64) -> i64 |
| 518 | func cd_notes_load(dir: *u8, dom: *u8, names: *i64, np: i64, recs: *i64, cap: i64, bufout: *i64, stats: *i64) -> i64 |
| 553 | func cd_notes_wrap(text: *u8, n: i64, maxch: i64, maxlines: i64, loff: *i64, llen: *i64) -> i64 called by 1: main |
| 579 | func cd_iso_x(ox: i64, x: i64, y: i64, unit: i64) -> i64 { return ox + ((x - y) * CD_ISO_COS_PERMIL / CD_PERMIL) * unit / CD_PERMIL } called by 1: main |
| 580 | func cd_iso_y(oy: i64, x: i64, y: i64, z: i64, unit: i64) -> i64 { return oy + ((x + y) * CD_ISO_SIN_PERMIL / CD_PERMIL) * unit / CD_PERMIL - z * unit / CD_PERMIL } called by 1: main |
| 582 | func cd_day_of(epoch: i64) -> i64 { return epoch / CD_SECS_PER_DAY } |
| 583 | func cd_spine_path(dir: *u8, dom: *u8, out: *u8) -> i64 |
| 591 | func cd_field(line: *u8, n: i64, k: i64, off: *i64, len: *i64) -> i64 |
| 607 | func cd_field_int(line: *u8, n: i64, k: i64) -> i64 called by 4: cd_spine_historycd_spine_trailcd_spine_has_daycd_spine_days calls 3: sys_mmapcd_fieldcd_atoi_n |
| 613 | func cd_field_eq(line: *u8, n: i64, k: i64, s: *u8) -> i64 |
| 623 | func cd_row_is(line: *u8, n: i64) -> i64 |
| 629 | func cd_count_lines(buf: *u8, n: i64) -> i64 called by 1: main |
| 637 | func cd_spine_history(buf: *u8, n: i64, player: *u8, today: i64, hist: *i64) -> i64 |
| 672 | func cd_trail_rec(recs: *i64, k: i64) -> *i64 { return (recs as i64 + k * CD_HIST_W * CD_I64_BYTES) as *i64 } |
| 673 | func cd_spine_trail(buf: *u8, n: i64, player: *u8, today: i64, recs: *i64, cap: i64) -> i64 |
| 705 | func cd_spine_has_day(buf: *u8, n: i64, day: i64) -> i64 |
| 719 | func cd_spine_days(buf: *u8, n: i64, days: *i64, rows: *i64, mrows: *i64, cap: i64) -> i64 |
| 739 | func cd_spine_append(dir: *u8, dom: *u8, epoch: i64, names: *i64, out: *i64, np: i64, nr: i64) -> i64 |
| 787 | func cd_sym_bare(s: *u8) -> *u8 called by 1: cd_sym_is_substrate |
| 793 | func cd_bytes_eq_str(a: *u8, n: i64, s: *u8) -> i64 |
| 801 | func cd_sym_is_substrate(plan: *u8, pn: i64, sym: *u8) -> i64 called by 2: maincd_substrate_mask calls 6: cd_sym_barecd_slensys_mmapcd_row_tag_iscd_fieldcd_bytes_eq_str |
| 851 | func cd_substrate_mask(plan: *u8, pn: i64, syms: *i64, rown: i64, mask: *i64) -> i64 |