feat(spectrum): min_intv-truncated backward reseed interval + FFI - #29
Conversation
Adds mem_search_backward_truncated_interval + the
prmi_mem_search_backward_truncated_interval FFI — the consumer's
zz_left_span_reseed seed emission in one call: the largest left span L with
occ(L) >= min_intv (floored at anchor_len), returned with its EXACT forward SA
interval (MemMatch { match_len: L, sa_start, occ }).
Locates L by a gallop-down + binary search whose predicate is
mem_search_capped(window, min_intv).occ >= min_intv (#28) — exact, never gallops
past min_intv — then recovers L's interval with one uncapped mem_search. span_max
from mem_search_backward (or, when est_hint != 0, the .isa-hinted
mem_search_backward_from_hint). est_hint only affects probe count.
Byte-identical to an independent oracle (truncated_span_oracle's L* + mem_search)
across the proptest; +FFI plumbing test. Checked anchor_end, packed-pac guard,
packed_pac_bytes in the FFI. This is the slow-but-exact binary-search form; the
RC-downward _interval_rc swaps into the FFI later. v0.3 perf series.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR introduces ChangesBackward Truncated Interval Search
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Add `forward_truncate_below_maximal`, the FORWARD analogue of the TRUNC_IV backward family (#27/#29/#30) for the reseed's right bound. Given a query and its already-found maximal match whose `occ < min_intv`, it finds the largest length L < match_len whose prefix occurs >= min_intv times and returns that interval (or the zero MemMatch when none qualifies). Forward PREFIX intervals nest directly (fixed start, shrinking end: query[..L] is a superset of query[..L+1]), unlike the LEFT reseed where prepending bases breaks forward nesting and forces the RC walk. So the walk carries [lo, hi) outward from the maximal interval as L shrinks — a short shares_prefix scan capped at min_intv per step, no model launch. `want_interval == false` returns only L* (the driver's next_pivot use); `true` recovers the exact interval by galloping find_boundary out from the capped walk's interior seed (seed-independent, so byte-identical to a cold mem_search). Adapted to main: 6-arg shares_prefix/ref_less (no keyed_compare_mask). Verified byte-identical against an independent per-length mem_search oracle across reference-lifted queries and a spread of min_intv. Pub primitive with no in-tree caller until the collect reseed module lands (the proptest is its only consumer).
Add `forward_truncate_below_maximal`, the FORWARD analogue of the TRUNC_IV backward family (#27/#29/#30) for the reseed's right bound. Given a query and its already-found maximal match whose `occ < min_intv`, it finds the largest length L < match_len whose prefix occurs >= min_intv times and returns that interval (or the zero MemMatch when none qualifies). Forward PREFIX intervals nest directly (fixed start, shrinking end: query[..L] is a superset of query[..L+1]), unlike the LEFT reseed where prepending bases breaks forward nesting and forces the RC walk. So the walk carries [lo, hi) outward from the maximal interval as L shrinks — a short shares_prefix scan capped at min_intv per step, no model launch. `want_interval == false` returns only L* (the driver's next_pivot use); `true` recovers the exact interval by galloping find_boundary out from the capped walk's interior seed (seed-independent, so byte-identical to a cold mem_search). Adapted to main: 6-arg shares_prefix/ref_less (no keyed_compare_mask). Verified byte-identical against an independent per-length mem_search oracle across reference-lifted queries and a spread of min_intv. Pub primitive with no in-tree caller until the collect reseed module lands (the proptest is its only consumer).
Add `forward_truncate_below_maximal`, the FORWARD analogue of the TRUNC_IV backward family (#27/#29/#30) for the reseed's right bound. Given a query and its already-found maximal match whose `occ < min_intv`, it finds the largest length L < match_len whose prefix occurs >= min_intv times and returns that interval (or the zero MemMatch when none qualifies). Forward PREFIX intervals nest directly (fixed start, shrinking end: query[..L] is a superset of query[..L+1]), unlike the LEFT reseed where prepending bases breaks forward nesting and forces the RC walk. So the walk carries [lo, hi) outward from the maximal interval as L shrinks — a short shares_prefix scan capped at min_intv per step, no model launch. `want_interval == false` returns only L* (the driver's next_pivot use); `true` recovers the exact interval by galloping find_boundary out from the capped walk's interior seed (seed-independent, so byte-identical to a cold mem_search). Adapted to main: 6-arg shares_prefix/ref_less (no keyed_compare_mask). Verified byte-identical against an independent per-length mem_search oracle across reference-lifted queries and a spread of min_intv. Pub primitive with no in-tree caller until the collect reseed module lands (the proptest is its only consumer).
v0.3 perf series (authored fresh on
main; built on #28'smem_search_capped).What
Adds
mem_search_backward_truncated_interval+ theprmi_mem_search_backward_truncated_intervalFFI — the consumer'szz_left_span_reseedseed emission in one call: the largest left-extension spanLwithocc(L) >= min_intv(floored atanchor_len), returned with its exact forward SA interval(match_len: L, sa_start, occ).How
Gallop-down + binary search to find
L, predicatemem_search_capped(window, min_intv).occ >= min_intv(#28 — exact, never gallops pastmin_intv), then one uncappedmem_searchto recoverL's interval. The binary search is sound because the predicate is monotone (occ(L)non-increasing inL).span_maxfrommem_search_backward(or, with a validest_hint, the hintedmem_search_backward_from_hint).Byte-identity
Verified against an independent oracle (
truncated_span_oracle'sL*+mem_search) across the proptest; + an FFI plumbing/contract test.Self-review caught a real doc bug
/coderabbitai-review(pre-PR) added anest_hint != 0test asserting "only affects probe count" — it failed, revealing thatmem_search_backward_from_hinttrusts the hint (it must be the inverse-SA of the anchor's locus, not any in-interval index). Corrected the docs to state theno_searchcontract and removed the test that used an invalid hint (theest_hintpath is covered by #19's reference-liftedmem_search_backward_from_hinttests; a random-read proptest can't construct a valid locus hint).Scope
This is the slow-but-exact binary-search form; the faster RC-downward
_interval_rcswaps into the FFI later. Checkedanchor_end, packed-pac guard,packed_pac_bytesin the FFI.Summary by CodeRabbit
New Features
Tests