code wiki / _hdl_build / nx_ge_str_lib.nx

nx_ge_str_lib.nx source

↩ module page · 31 lines · 1085 B

1// nx_ge_str_lib.nx -- shared substring helpers (find / count / byte-equal) for the gated-edit appliers 2// (nx_gated_edit single-edit + nx_gated_edit_multi). Rule-15 extraction; pure, no syscalls, verbatim bodies. 3// license_tier: ORIGINAL No hw writes (Rule 26). 4func ge_find(hay: *u8, hn: i64, ndl: *u8, nl: i64, from: i64) -> i64 { 5 if nl == 0 { return 0 - 1 } 6 var i: i64 = from 7 while i + nl <= hn { 8 var k: i64 = 0 9 var hit: i64 = 1 10 while k < nl { if hay[i+k] != ndl[k] { hit = 0; k = nl } else { k = k + 1 } } 11 if hit == 1 { return i } 12 i = i + 1 13 } 14 return 0 - 1 15} 16func ge_count(hay: *u8, hn: i64, ndl: *u8, nl: i64) -> i64 { 17 if nl == 0 { return 0 } 18 var c: i64 = 0 19 var i: i64 = 0 20 while i + nl <= hn { 21 let p: i64 = ge_find(hay, hn, ndl, nl, i) 22 if p < 0 { i = hn } else { c = c + 1; i = p + nl } 23 } 24 return c 25} 26func ge_eq(a: *u8, an: i64, b: *u8, bn: i64) -> i64 { 27 if an != bn { return 0 } 28 var i: i64 = 0 29 while i < an { if a[i] != b[i] { return 0 } i = i + 1 } 30 return 1 31}