code wiki / (root) / nx_temporal_index.nx

nx_temporal_index.nx source

↩ module page · 48 lines · 1941 B

1// nx_temporal_index.nx -- LIB: the (host,path)->[(date,capture)] temporal index = the "browse day-by-day" backbone. 2// Given parallel capture arrays (keys = host+path string pointers, dates = YYYYMMDD ints), ti_query returns the 3// capture AS IT EXISTED on a target date: the most-recent capture at-or-before the target (the Wayback "as-of" 4// semantics), else the earliest available capture for that key. Exact key match (no prefix bleed). Pure/in-memory 5// for this gate; seg_store persistence + WARC-Date(ISO8601)->YYYYMMDD parsing + R2 record-feed compose in a 6// follow-on. license_tier: ORIGINAL 7import "nx_syscalls.nx" 8 9// exact NUL-terminated string equality. 10func ti_keq(a: *u8, b: *u8) -> i64 { 11 var i: i64 = 0 12 var r: i64 = 0 - 1 13 while r < 0 { 14 let ca: i64 = a[i] as i64 15 let cb: i64 = b[i] as i64 16 if ca != cb { r = 0 } else { if ca == 0 { r = 1 } else { i = i + 1 } } 17 } 18 return r 19} 20 21// returns the array index of the best capture for qkey as-of qdate, or 0-1 if the key is absent. 22// pass 1: most-recent capture with date <= qdate (the snapshot as it existed by then) 23// pass 2 (fallback): earliest capture for the key (if every capture is after qdate) 24func ti_query(keyptrs: *i64, dates: *i64, count: i64, qkey: *u8, qdate: i64) -> i64 { 25 var best: i64 = 0 - 1 26 var bestdate: i64 = 0 - 1 27 var i: i64 = 0 28 while i < count { 29 if ti_keq((keyptrs[i]) as *u8, qkey) == 1 { 30 let d: i64 = dates[i] 31 if d <= qdate { if d > bestdate { bestdate = d; best = i } } 32 } 33 i = i + 1 34 } 35 if best >= 0 { return best } 36 var bi: i64 = 0 - 1 37 var bd: i64 = 0 38 i = 0 39 while i < count { 40 if ti_keq((keyptrs[i]) as *u8, qkey) == 1 { 41 let d: i64 = dates[i] 42 if bi < 0 { bi = i; bd = d } else { if d < bd { bd = d; bi = i } } 43 } 44 i = i + 1 45 } 46 return bi 47} 48func main() -> i64 { return 0 }