code wiki / _hdl_build / nx_galx_sortindex.nx

nx_galx_sortindex.nx

buildroot/runtime/_hdl_build/nx_galx_sortindex.nx

23664 B468 linesdepth 2pulls 2 transitivereach 3 importersview sourcekind librarytopic galx
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_galx_sortindex.nx nx_gallery_serve.nx nx_galx_sortindex_gate.nx nx_galx_sortserve_gate.nx

imports: nx_syscalls.nx

imported by: nx_gallery_serve.nxnx_galx_sortindex_gate.nxnx_galx_sortserve_gate.nx

structs

none

consts

20const K_MAGIC_1000003: i64 = 1000003
21const K_MAGIC_2000000: i64 = 2000000
22const K_MAGIC_65536: i64 = 65536
23const K_MAGIC_1500000: i64 = 1500000
24const K_MAGIC_2048: i64 = 2048
25const K_MAGIC_262144: i64 = 262144

functions

29func si_first_int(s: *u8, from: i64, to: i64) -> i64
called by 1: si_build_index
42func si_wb64(buf: *u8, off: i64, v: i64) -> i64
48func si_rb64(buf: *u8, off: i64) -> i64
55func si_fsize(path: *u8) -> i64
64func si_msort(keys: *i64, ids: *i64, tk: *i64, ti: *i64, N: i64) -> i64
90func si_build_index(key_file: *u8, out_path: *u8, fresh_file: *u8) -> i64
135func 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 }
136func si_u(dst: *u8, off: i64, v: i64) -> i64
called by 3: si_okjsonss_emit_pagemain calls 1: sys_mmap
142func 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
143func si_okjson(rbuf: *u8, body: *u8, blen: i64) -> i64
151func si_qint(req: *u8, rn: i64, key: *u8, deflt: i64) -> i64
162func si_eff_offset(req: *u8, rn: i64, count: i64, o0: i64) -> i64
170func ss_path_cat(b: *u8, ls: i64, le: i64, rb: *u8, rsz: i64) -> i64
194func ss_sortidx_path(keyc: i64, wantc: i64, out: *u8) -> i64
202func ss_write_index(path: *u8, stamp: i64, arr: *i64, cnt: i64) -> i64
214func ss_fsize0(path: *u8) -> i64 { let s: i64 = si_fsize(path); if s < 0 { return 0 } return s }
called by 1: ss_live_stamp calls 1: si_fsize
215func 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 }
217func ss_load_hidden(bm: *u8) -> i64
243func ss_is_hidden(bm: *u8, id: i64) -> i64 { if id >= K_MAGIC_2000000 { return 0 } if (bm[id >> 3] as i64 & (1 << (id & 7))) != 0 { return 1 } return 0 }
246func ss_emit_page(rbuf: *u8, cb: *u8, count: i64, eo0: i64, dir: i64, n: i64) -> i64
263func ss_build_size(wantc: i64) -> i64
298func ss_emit_size(rbuf: *u8, req: *u8, rn: i64, wantc: i64, dir: i64, o0: i64, n: i64) -> i64
312func ss_build_runtime(wantc: i64) -> i64
359func ss_emit_runtime(rbuf: *u8, req: *u8, rn: i64, wantc: i64, dir: i64, o0: i64, n: i64) -> i64
381func ss_lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c }
called by 1: ss_namecmp
383func ss_namecmp(buf: *u8, oa: i64, la: i64, ob: i64, lb: i64) -> i64
called by 1: ss_msort_name calls 1: ss_lc
396func ss_msort_name(buf: *u8, bo: *i64, bl: *i64, ids: *i64, tbo: *i64, tbl: *i64, tid: *i64, N: i64) -> i64
called by 1: ss_build_name calls 1: ss_namecmp
420func ss_build_name(wantc: i64) -> i64
456func ss_emit_name(rbuf: *u8, req: *u8, rn: i64, wantc: i64, dir: i64, o0: i64, n: i64) -> i64