def find.go

bend-kit-bytes@0.3.3.0 · bytes.bend:429

import bend-kit-bytes@0.3.3.0/bytes.bend as Bytes
import Base

429# ponytail: naive search; a mismatch costs one byte read per position, but a repetitive needle is O(len * needle). Add a SWAR scan or two-way search if find gets hot.
430# f counts the positions left after i.
431def find.go(f: Nat, r: Array<U32> & Bool, +needle: String, +i: U32, +up: Bool) -> Array<U32> & Maybe<&2, U32>:
432  match f:
433    case 0n:
434      (a, hit) = r
435      (a, Bool.pick(Maybe<&2, U32>, hit, Some{i}, None{}))
436    case 1n+p:
437      (a, hit) = r
438      match hit:
439        case True{}:
440          (a, Some{i})
441        case False{}:
442          find.go(p, at(a, needle, step(up, i)), needle, step(up, i), up)

Uses (11)

Used by (1)