code wiki / _hdl_build / nx_galx_durbin.nx

nx_galx_durbin.nx source

↩ module page · 28 lines · 1624 B

1// nx_galx_durbin.nx -- standalone refresher: (re)build galx_dur.bin from galx_dur.raw so the gallery's 2// /vid/<id>/dur seekbar lookup is O(1) (one 8-byte seek) instead of a 16 MB PCR re-scan. Run after the 3// durindex appends new durations -- NO gallery restart needed (the gallery reads galx_dur.bin fresh on 4// each /dur, exactly like nx_galx_vidoff refreshes galx_vid_off.bin). Idempotent; safe to run while the 5// durindex is still writing (append-only -> earlier ids stay correct). license_tier: ORIGINAL 6import "nx_syscalls.nx" 7import "nx_galx_durbin_lib.nx" 8 9func rp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 10func rn(v: i64) -> i64 { 11 var m: i64=v; var neg: i64=0; if m<0 { neg=1; m=0-m } 12 let b: *u8=sys_mmap(32); var i: i64=32 13 if m==0 { i=i-1; b[i]=(48 as u8) } 14 while m>0 { let q: i64=m/10; i=i-1; b[i]=((48+(m-q*10)) as u8); m=q } 15 if neg==1 { i=i-1; b[i]=(45 as u8) } 16 sys_write(1, ((b as i64)+i) as *u8, 32-i); return 0 17} 18 19func main(argc: i64, argv: *i64) -> i64 { 20 // vidpaths size = the freshness key: line N -> video N is valid only while galx_vid_paths.tsv is unchanged. 21 var vps: i64 = 0 22 let tfd: i64 = sys_openat_rd("knowledge/status/galx_vid_paths.tsv" as *u8) 23 if tfd >= 0 { vps = sys_lseek(tfd, 0, 2); sys_close(tfd) } 24 let n: i64 = db_build("knowledge/status/galx_dur.raw" as *u8, "knowledge/status/galx_dur.bin" as *u8, vps) 25 if n < 0 { rp("durbin: cannot read galx_dur.raw\n" as *u8); return 1 } 26 rp("durbin: galx_dur.bin built, n=" as *u8); rn(n); rp(" vps=" as *u8); rn(vps); rp("\n" as *u8) 27 return 0 28}