code wiki / (root) / nx_cdmap_lib.nx

nx_cdmap_lib.nx

buildroot/runtime/nx_cdmap_lib.nx

39744 B859 linesdepth 2pulls 2 transitivereach 37 importersview sourcekind librarytopic cdmap
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_cdmap_lib.nx nx_cdmap_gate.nx nx_compare_feed_lib.nx nx_swcompare_lib.nx

imports: nx_syscalls.nx

imported by: nx_cdmap_gate.nxnx_compare_feed_lib.nxnx_swcompare_lib.nx

structs

none

consts

47const CD_PTS_BEST: i64 = 3
48const CD_PTS_YES: i64 = 2
49const CD_PTS_PART: i64 = 1
50const CD_PTS_NO: i64 = 0
51const CD_CODE_NO: i64 = 0
52const CD_CODE_YES: i64 = 1
53const CD_CODE_BEST: i64 = 2
54const CD_CODE_PART: i64 = 3
55const CD_NISHI_ABSENT: i64 = 0
56const CD_NISHI_PRESENT: i64 = 1
57const CD_NISHI_EXCEED: i64 = 2
58const CD_PERMIL: i64 = 1000
59const CD_W: i64 = 4 // result words per player
60const CD_R_C: i64 = 0
61const CD_R_D: i64 = 1
62const CD_R_BREADTH: i64 = 2 // raw depth-weighted points held
63const CD_R_HELD: i64 = 3
64const CD_Q_ABSENT: i64 = 0
65const CD_Q_ASPIRATIONAL: i64 = 1
66const CD_Q_MAINSTREAM: i64 = 2
67const CD_Q_PERIPHERAL: i64 = 3
68const CD_Q_UNCONVENTIONAL: i64 = 4
69const CD_SECS_PER_DAY: i64 = 86400
70const CD_I64_BYTES: i64 = 8
71const CD_SPINE_DIR: *u8 = "knowledge/status/cdmap/"
72const CD_SPINE_EXT: *u8 = ".spine"
73const CD_SPINE_TAG: *u8 = "cd|"
74const CD_SPINE_TAGLEN: i64 = 3
75const CD_SPINE_NF: i64 = 10
76const CD_F_TAG: i64 = 0
77const CD_F_EPOCH: i64 = 1
78const CD_F_DAY: i64 = 2
79const CD_F_PLAYER: i64 = 3
80const CD_F_C: i64 = 4
81const CD_F_D: i64 = 5
82const CD_F_BREADTH: i64 = 6
83const CD_F_ROWS: i64 = 7
84const CD_F_PLAYERS: i64 = 8
85const CD_F_HELD: i64 = 9
86const CD_PATH_CAP: i64 = 600
87const CD_ROW_CAP: i64 = 512
88const CD_NUM_SCRATCH: i64 = 32
89const CD_DIR_MODE: i64 = 493 // 0755
90const CD_FILE_MODE: i64 = 420 // 0644
91const CD_CH_PIPE: i64 = 124
92const CD_CH_LF: i64 = 10
93const CD_CH_CR: i64 = 13
94const CD_CH_HASH: i64 = 35
95const CD_CH_SPACE: i64 = 32
96const CD_CH_ZERO: i64 = 48
97const CD_CH_NINE: i64 = 57
98const CD_CH_MINUS: i64 = 45
99const CD_TEN: i64 = 10
101const CD_HIST_W: i64 = 14
102const CD_H_FC: i64 = 0
103const CD_H_FD: i64 = 1
104const CD_H_FDAY: i64 = 2
105const CD_H_PC: i64 = 3
106const CD_H_PD: i64 = 4
107const CD_H_PDAY: i64 = 5
108const CD_H_DAYS: i64 = 6
109const CD_H_LASTDAY: i64 = 7
110const CD_H_FB: i64 = 8 // first-day breadth points
111const CD_H_FH: i64 = 9 // first-day held
112const CD_H_FROWS: i64 = 10 // first-day matrix rows
113const CD_H_PB: i64 = 11 // previous-day breadth points
114const CD_H_PH: i64 = 12 // previous-day held
115const CD_H_PROWS: i64 = 13 // previous-day matrix rows
117const CD_AX_C: i64 = 0
118const CD_AX_D: i64 = 1
119const CD_AX_BREADTH: i64 = 2
120const CD_AX_DEPTH: i64 = 3
121const CD_AX_MOMENTUM: i64 = 4
122const CD_AX_N: i64 = 5
123const CD_AX_NONE: i64 = 0 - 1
124const CD_MOM_SPAN: i64 = 2000 // momentum ranges -1000..1000; plotted on 0..1000
125const CD_VIEW_CUT: i64 = 0
126const CD_VIEW_CUBE: i64 = 1
127const CD_CUT_AXES: i64 = 2
128const CD_CUBE_AXES: i64 = 3
129const CD_VIEW_DIR: *u8 = "knowledge/compare/"
130const CD_VIEW_EXT: *u8 = ".cdmap"
131const CD_VIEW_CUT_TAG: *u8 = "cut|"
132const CD_VIEW_CUBE_TAG: *u8 = "cube|"
133const CD_VIEW_ABSENT: i64 = 0 // no conf or no row for that view: the caller takes the default
134const CD_VIEW_REFUSED: i64 = 0 - 1 // a row named an axis the registry does not have
136const CD_ISO_COS_PERMIL: i64 = 866
137const CD_ISO_SIN_PERMIL: i64 = 500
139const CD_HIST_WHICH_FIRST: i64 = 0
140const CD_HIST_WHICH_PREV: i64 = 1
414const CD_NOTE_EXT: *u8 = ".cdnotes"
415const CD_NOTE_TAG: *u8 = "note|"
416const CD_NOTE_AT: *u8 = "at:"
417const CD_NOTE_AT_LEN: i64 = 3
418const CD_NOTE_TEXT_MAX: i64 = 120
419const CD_NOTE_W: i64 = 12
420const CD_N_KIND: i64 = 0
421const CD_N_PLAYER: i64 = 1
422const CD_N_X: i64 = 2
423const CD_N_Y: i64 = 3
424const CD_N_TOFF: i64 = 4
425const CD_N_TLEN: i64 = 5
426const CD_N_IDOFF: i64 = 6
427const CD_N_IDLEN: i64 = 7
428const CD_N_SOFF: i64 = 8
429const CD_N_SLEN: i64 = 9
430const CD_N_BOFF: i64 = 10
431const CD_N_BLEN: i64 = 11
432const CD_NK_PLAYER: i64 = 1
433const CD_NK_AT: i64 = 2
434const CD_NF_ID: i64 = 1
435const CD_NF_ANCHOR: i64 = 2
436const CD_NF_TEXT: i64 = 3
437const CD_NF_SINCE: i64 = 4
438const CD_NF_BY: i64 = 5
439const CD_NS_ROWS: i64 = 0 // stats: rows tagged note|
440const CD_NS_REFUSED: i64 = 1 // rows refused (counted, never rendered)
441const CD_NS_W: i64 = 2
442const CD_CH_COMMA: i64 = 44
443const CD_NOTE_REFUSED: i64 = 0 - 1
778const CD_ROLE_SUBSTRATE: *u8 = "substrate"
779const CD_ABSENT_PFX: *u8 = "_ABSENT_:"
780const CD_ABSENT_PFX_LEN: i64 = 9
781const CD_RUNG_TAG: *u8 = "rung|"
782const CD_RUNGROLE_TAG: *u8 = "rungrole|"
783const CD_RUNG_F_ID: i64 = 1
784const CD_RUNG_F_SYM: i64 = 3
785const CD_ROLE_F_ID: i64 = 1
786const CD_ROLE_F_ROLE: i64 = 2

functions

142func cd_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
143func 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 }
146func cd_cat_safe(d: *u8, o: i64, s: *u8) -> i64
called by 1: cd_spine_append
157func cd_catn(d: *u8, o: i64, v: i64) -> i64
called by 1: cd_spine_append calls 1: sys_mmap
167func cd_signed(v: i64, neg: i64) -> i64 { if neg == 1 { return 0 - v } return v }
called by 1: cd_atoi_n
169func cd_atoi(s: *u8) -> i64 { return cd_atoi_n(s, cd_slen(s)) }
called by 1: main calls 2: cd_atoi_ncd_slen
171func cd_atoi_n(s: *u8, n: i64) -> i64
185func cd_isqrt(v: i64) -> i64
called by 1: main
192func cd_clamp_permil(v: i64) -> i64 { if v < 0 { return 0 } if v > CD_PERMIL { return CD_PERMIL } return v }
194func cd_pts(code: i64) -> i64
called by 1: main
201func cd_nishi_pts(nishi: i64) -> i64
called by 1: main
207func cd_compute(pts: *i64, np: i64, nr: i64, out: *i64) -> i64
called by 1: main calls 1: sys_mmap
252func cd_mean(out: *i64, np: i64, field: i64) -> i64
called by 1: main
259func cd_quadrant(c: i64, d: i64, cmean: i64, dmean: i64, held: i64) -> i64
called by 1: main
265func cd_quadrant_name(q: i64) -> *u8
273func cd_axis_name(id: i64) -> *u8
called by 2: maincd_axis_id
281func cd_name_eq_n(name: *u8, s: *u8, n: i64) -> i64
288func cd_axis_id(s: *u8, n: i64) -> i64
293func cd_breadth_permil(points: i64, rows: i64) -> i64 { if rows <= 0 { return 0 } return CD_PERMIL * points / (CD_PTS_BEST * rows) }
294func cd_depth_permil(points: i64, held: i64) -> i64 { if held <= 0 { return 0 } return CD_PERMIL * points / (CD_PTS_BEST * held) }
295func cd_momentum_known(hist: *i64) -> i64 { if hist[CD_H_PDAY] > 0 { return 1 } return 0 }
called by 1: cd_momentum
297func cd_momentum(out: *i64, p: i64, hist: *i64) -> i64
302func cd_mom_plot(m: i64) -> i64 { return cd_clamp_permil((m + CD_PERMIL) * CD_PERMIL / CD_MOM_SPAN) }
304func cd_axis_value(out: *i64, p: i64, nr: i64, hist: *i64, id: i64) -> i64
313func cd_axis_plot(out: *i64, p: i64, nr: i64, hist: *i64, id: i64) -> i64
318func cd_hist_axis_plot(hist: *i64, which: i64, id: i64) -> i64
333func cd_axis_mean_plot(out: *i64, np: i64, nr: i64, hist: *i64, id: i64) -> i64
called by 1: main calls 1: cd_axis_plot
341func cd_view_default(view: i64, ids: *i64) -> i64
called by 1: main
347func 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
348func cd_view_path(dir: *u8, dom: *u8, out: *u8) -> i64
356func cd_view_row(line: *u8, n: i64, view: i64, ids: *i64) -> i64
372func cd_row_tag_is(line: *u8, n: i64, tag: *u8) -> i64
381func cd_view_conf(dir: *u8, dom: *u8, view: i64, ids: *i64) -> i64
444func cd_notes_path(dir: *u8, dom: *u8, out: *u8) -> i64
451func cd_note_rec(recs: *i64, k: i64) -> *i64 { return (recs as i64 + k * CD_NOTE_W * CD_I64_BYTES) as *i64 }
called by 2: maincd_notes_load
453func cd_notes_player(line: *u8, off: i64, len: i64, names: *i64, np: i64) -> i64
called by 1: cd_note_row calls 1: cd_name_eq_n
459func cd_note_at(line: *u8, off: i64, len: i64, xy: *i64) -> i64
475func cd_note_row(line: *u8, n: i64, base: i64, names: *i64, np: i64, rec: *i64) -> i64
518func cd_notes_load(dir: *u8, dom: *u8, names: *i64, np: i64, recs: *i64, cap: i64, bufout: *i64, stats: *i64) -> i64
553func cd_notes_wrap(text: *u8, n: i64, maxch: i64, maxlines: i64, loff: *i64, llen: *i64) -> i64
called by 1: main
579func 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
580func 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
582func cd_day_of(epoch: i64) -> i64 { return epoch / CD_SECS_PER_DAY }
called by 2: maincd_spine_append
583func cd_spine_path(dir: *u8, dom: *u8, out: *u8) -> i64
591func cd_field(line: *u8, n: i64, k: i64, off: *i64, len: *i64) -> i64
607func cd_field_int(line: *u8, n: i64, k: i64) -> i64
613func cd_field_eq(line: *u8, n: i64, k: i64, s: *u8) -> i64
623func cd_row_is(line: *u8, n: i64) -> i64
629func cd_count_lines(buf: *u8, n: i64) -> i64
called by 1: main
637func cd_spine_history(buf: *u8, n: i64, player: *u8, today: i64, hist: *i64) -> i64
672func cd_trail_rec(recs: *i64, k: i64) -> *i64 { return (recs as i64 + k * CD_HIST_W * CD_I64_BYTES) as *i64 }
called by 2: maincd_spine_trail
673func cd_spine_trail(buf: *u8, n: i64, player: *u8, today: i64, recs: *i64, cap: i64) -> i64
705func cd_spine_has_day(buf: *u8, n: i64, day: i64) -> i64
719func cd_spine_days(buf: *u8, n: i64, days: *i64, rows: *i64, mrows: *i64, cap: i64) -> i64
called by 1: main calls 2: cd_row_iscd_field_int
739func cd_spine_append(dir: *u8, dom: *u8, epoch: i64, names: *i64, out: *i64, np: i64, nr: i64) -> i64
787func cd_sym_bare(s: *u8) -> *u8
called by 1: cd_sym_is_substrate
793func cd_bytes_eq_str(a: *u8, n: i64, s: *u8) -> i64
called by 1: cd_sym_is_substrate calls 1: cd_slen
801func cd_sym_is_substrate(plan: *u8, pn: i64, sym: *u8) -> i64
851func cd_substrate_mask(plan: *u8, pn: i64, syms: *i64, rown: i64, mask: *i64) -> i64
called by 1: main calls 1: cd_sym_is_substrate