feat(spectrum): cap-bounded forward mem_search (gap A, min_intv-bounded SMEM) - #28
Conversation
|
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)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughAdds a cap-bounded forward maximal match: ChangesCapped forward maximal match query
Sequence DiagramsequenceDiagram
participant C as Caller
participant FFI as prmi_mem_search_capped
participant Core as LearnedIndex::mem_search_capped
participant MaxLen as forward_maximal_len
participant Expand as IntervalExpansion
C->>FFI: call(query, cap, pac, out ptrs)
FFI->>FFI: clear_last_error
FFI->>FFI: validate pointers and query_len
FFI->>FFI: pack PAC bytes
FFI->>Core: call mem_search_capped(packed pac, query, max_intv)
Core->>MaxLen: compute match_len and insertion point
MaxLen-->>Core: return match_len and ip
Core->>Expand: select seed (ip or ip-1)
Expand->>Expand: expand left/right while occ <= max_intv
alt interval within cap
Expand-->>Core: return sa_start and occ
else interval exceeds cap
Expand-->>Core: return partial sa_start and occ = max_intv + 1
end
Core-->>FFI: MemMatch result
FFI->>FFI: write out_match_len, out_sa_start, out_occ
FFI-->>C: return 0 (success)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@prmi-sys/tests/spectrum_ffi.rs`:
- Around line 1307-1326: Replace the weak inequality check with a strict
equality to enforce the capped-occ contract: when calling prmi_mem_search_capped
with cap = occ - 1, assert that the returned c2occ equals cap + 1 (which is occ)
instead of only checking c2occ > cap; update the assertion on c2occ (around the
prmi_mem_search_capped call) to assert_eq!(c2occ, occ, "occ==cap+1: expected
short-circuit return of cap+1") so the test fails if the implementation returns
the full true interval count.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 41b7ff22-f407-4a31-b978-229514481afb
📒 Files selected for processing (3)
prmi-sys/src/lib.rsprmi-sys/tests/spectrum_ffi.rsprmi/src/index/spectrum.rs
…ed SMEM) Adds mem_search_capped + the prmi_mem_search_capped FFI — BWA-MEME's min_intv-bounded SMEM interval counting. The maximal match_len is exact; the SA interval is BYTE-IDENTICAL to mem_search when the true occ <= max_intv, else the outward interval scan stops early at occ == max_intv + 1 with the wide-interval gallop skipped (the dominant cost on the repetitive tail), so sa_start is then a partial bound and the caller treats occ > max_intv as too repetitive. Bracketed O(log) launch; derives the in-interval seed from forward_maximal_len's insertion point with one shares_prefix probe (same as the truncated span). FFI uses packed_pac_bytes (the narrowing guard), not a raw div_ceil cast. Byte-identity proptest (capped == mem_search for occ <= cap) + an FFI test. The next building block toward the interval-returning truncated reseed. v0.3 perf series.
778340e to
82fd7e5
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
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.
v0.3 perf series (authored fresh on
main; built on #26'sforward_maximal_len → (match_len, ip)and reusing #27's in-interval seed derivation).What
Adds
mem_search_capped+ theprmi_mem_search_cappedFFI — BWA-MEME'smin_intv-bounded SMEM interval counting (gap A).match_lenis always exact.occ <= max_intv, the SA interval (sa_start,occ) is byte-identical tomem_search.occ > max_intv, the outward interval scan stops early and returnsocc == max_intv + 1with the wide-interval gallop skipped (the dominant cost on the repetitive tail), sosa_startis a partial bound — the caller treatsocc > max_intvas "too repetitive".How
Bracketed O(log) launch (
forward_maximal_len), in-interval seed derived from the insertion point with oneshares_prefix(ip-1)probe (same asmem_search_backward_truncated_span_rc), then a capped outward scan.Tests
mem_search_capped_equals_uncapped_under_cap(proptest): byte-identity vsmem_searchforocc <= cap, short-circuitocc > capotherwise — across query lengths and caps straddling the true occ (incl. 0 and a huge value).mem_search_capped_ffi_matches_uncapped_under_cap: the FFI surface.Notes
FFI null-checks all three out-ptrs unconditionally (it always writes the interval, no
WANT_INTERVALflag) and usespacked_pac_bytes(the narrowing guard), not the original perf branch's rawdiv_ceilcast. This is the next building block toward the interval-returning truncated reseed.Self-reviewed with
/coderabbitai-reviewbefore opening (0 actionable; applied 1 nitpick — addedcap=0to the proptest spread).Summary by CodeRabbit
New Features
Tests