code wiki / _hdl_build / nx_galx_sortindex.nx
nx_galx_sortindex.nx
buildroot/runtime/_hdl_build/nx_galx_sortindex.nx
about
nx_galx_sortindex.nx -- LIBRARY (no main -> build the _gate): build a SORT-INDEX over the gallery's
recordings so the daemon can SORT BY an integer key (runtime, file-size, view-count, rating) at
O(1)-per-page instead of re-sorting every request (operator: "slow to sort"). R2 of the s-class
media-UI epic. Composes with the R1 discovery offset (gs_eff_offset): the serve reads this index
forward (ascending) or backward (descending) and paginates with the SAME pct/rand/offset logic, so a
single ascending index serves both sort directions.
FORMAT (big-endian u64 so the daemon reads it with the existing gs_rb64; SAME shape as the category
index galx_cat_<c>.bin so the serve reuses that reader):
[0..8) stamp = byte-size of the freshness file (vid_paths.tsv) -> stale-detect / rebuild-on-change
[8..16) count N
[16..) N x id = recording ids (0-based line numbers) sorted ASCENDING by key
The KEY comes from a "key file": one record per line, key = the first run of decimal digits on that
line. So it ingests nx_galx_durindex's out_dur.raw "dur_ms=<n>" lines directly, and any future size /
view-count key file. Line index i == recording id i (matches the daemon's id->line mapping); a blank
or key-less line becomes key 0 (keeps id alignment) and simply sorts first.
license_tier: ORIGINAL
dependencies 1 imports · 3 importers
imports: nx_syscalls.nx
imported by: nx_gallery_serve.nxnx_galx_sortindex_gate.nxnx_galx_sortserve_gate.nx
structs
| none |
consts
| 20 | const K_MAGIC_1000003: i64 = 1000003 |
| 21 | const K_MAGIC_2000000: i64 = 2000000 |
| 22 | const K_MAGIC_65536: i64 = 65536 |
| 23 | const K_MAGIC_1500000: i64 = 1500000 |
| 24 | const K_MAGIC_2048: i64 = 2048 |
| 25 | const K_MAGIC_262144: i64 = 262144 |
functions
| 29 | func si_first_int(s: *u8, from: i64, to: i64) -> i64 called by 1: si_build_index |
| 42 | func si_wb64(buf: *u8, off: i64, v: i64) -> i64 |
| 48 | func si_rb64(buf: *u8, off: i64) -> i64 |
| 55 | func si_fsize(path: *u8) -> i64 |
| 64 | func si_msort(keys: *i64, ids: *i64, tk: *i64, ti: *i64, N: i64) -> i64 |
| 90 | func si_build_index(key_file: *u8, out_path: *u8, fresh_file: *u8) -> i64 |
| 135 | func si_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64 = 0; while s[i] != (0 as u8) { dst[off+i] = s[i]; i = i + 1 } return off + i } |
| 136 | func si_u(dst: *u8, off: i64, v: i64) -> i64 |
| 142 | func si_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } called by 1: si_qint |
| 143 | func si_okjson(rbuf: *u8, body: *u8, blen: i64) -> i64 |
| 151 | func si_qint(req: *u8, rn: i64, key: *u8, deflt: i64) -> i64 |
| 162 | func si_eff_offset(req: *u8, rn: i64, count: i64, o0: i64) -> i64 |
| 170 | func ss_path_cat(b: *u8, ls: i64, le: i64, rb: *u8, rsz: i64) -> i64 |
| 194 | func ss_sortidx_path(keyc: i64, wantc: i64, out: *u8) -> i64 called by 6: ss_build_sizess_emit_sizess_build_runtimess_emit_runtimess_build_namess_emit_name calls 1: si_cat |
| 202 | func ss_write_index(path: *u8, stamp: i64, arr: *i64, cnt: i64) -> i64 called by 3: ss_build_sizess_build_runtimess_build_name calls 5: sys_mmapsi_wb64sys_openat_wrsys_writesys_close |
| 214 | func ss_fsize0(path: *u8) -> i64 { let s: i64 = si_fsize(path); if s < 0 { return 0 } return s } |
| 215 | func ss_live_stamp() -> i64 { return ss_fsize0("knowledge/status/galx_vid_paths.tsv" as *u8) + ss_fsize0("knowledge/status/galx_hidden.log" as *u8) * K_MAGIC_1000003 } called by 6: ss_build_sizess_emit_sizess_build_runtimess_emit_runtimess_build_namess_emit_name calls 1: ss_fsize0 |
| 246 | func ss_emit_page(rbuf: *u8, cb: *u8, count: i64, eo0: i64, dir: i64, n: i64) -> i64 |
| 263 | func ss_build_size(wantc: i64) -> i64 called by 1: ss_emit_size calls 10: sys_mmapsys_read_filess_load_hiddenss_path_catss_is_hiddensi_fsize+4 |
| 298 | func ss_emit_size(rbuf: *u8, req: *u8, rn: i64, wantc: i64, dir: i64, o0: i64, n: i64) -> i64 called by 2: gs_api_listmain calls 8: ss_live_stampsys_mmapss_sortidx_pathsys_read_filesi_rb64ss_build_size+2 |
| 312 | func ss_build_runtime(wantc: i64) -> i64 called by 1: ss_emit_runtime calls 10: sys_mmapsys_read_filesi_qintss_load_hiddenss_path_catss_is_hidden+4 |
| 359 | func ss_emit_runtime(rbuf: *u8, req: *u8, rn: i64, wantc: i64, dir: i64, o0: i64, n: i64) -> i64 called by 2: gs_api_listmain calls 10: ss_live_stampsys_mmapss_sortidx_pathsys_read_filesi_rb64ss_build_runtime+4 |
| 381 | func ss_lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c } called by 1: ss_namecmp |
| 383 | func ss_namecmp(buf: *u8, oa: i64, la: i64, ob: i64, lb: i64) -> i64 |
| 396 | func ss_msort_name(buf: *u8, bo: *i64, bl: *i64, ids: *i64, tbo: *i64, tbl: *i64, tid: *i64, N: i64) -> i64 |
| 420 | func ss_build_name(wantc: i64) -> i64 called by 1: ss_emit_name calls 9: sys_mmapsys_read_filess_load_hiddenss_path_catss_is_hiddenss_msort_name+3 |
| 456 | func ss_emit_name(rbuf: *u8, req: *u8, rn: i64, wantc: i64, dir: i64, o0: i64, n: i64) -> i64 called by 2: gs_api_listmain calls 8: ss_live_stampsys_mmapss_sortidx_pathsys_read_filesi_rb64ss_build_name+2 |