feat(spectrum): forward min_intv-truncated extension primitive - #31
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds LearnedIndex::forward_truncate_below_maximal: a capped outward SA-interval expansion that finds the largest shorter prefix L < maximal.match_len with occurrences >= min_intv, optionally recovering exact SA boundaries; includes a brute-force oracle, proptest validation, and a unit test for fail-closed malformed maximal inputs. ChangesForward Truncation Primitive
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 |
f9b10af to
7ff9c1a
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
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/src/index/spectrum.rs`:
- Around line 2217-2253: forward_truncate_below_maximal must validate packed
PACs and fail closed before calling shares_prefix to avoid panics on undersized
packed decoding; add an early guard in forward_truncate_below_maximal that, when
enc == PacEncoding::Packed, checks the provided pac buffer is large enough for
l_pac (or otherwise meets the packed-decode size requirements) and returns zero
on failure, so no packed decode unwraps occur inside shares_prefix or downstream
calls.
🪄 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: cf6d3336-0ad0-4ab7-a375-bcf71f954317
📒 Files selected for processing (1)
prmi/src/index/spectrum.rs
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).
7ff9c1a to
f422159
Compare
v0.3 perf series — PR-D1 of the
collect_smemscarve (the forward primitive the fused reseed driver needs; the collect module + FFI land in PR-D2 on top of this).What
Adds
forward_truncate_below_maximal, the forward analogue of the TRUNC_IV backward family (#27/#29/#30), for the reseed's right (forward) bound. Given a query and its already-found maximal match whoseocc < min_intv, it finds the largest lengthL < match_lenwhose prefix occurs>= min_intvtimes and returns that interval (or the zeroMemMatchwhen none qualifies).Why a forward walk works here (and the backward reseed needed RC)
Forward prefix intervals nest directly — fixed start, shrinking end:
query[..L]is a superset ofquery[..L+1]in forward SA. So the walk carries[lo, hi)outward from the maximal interval asLshrinks — a shortshares_prefixscan capped atmin_intvper step, no model launch. (Contrast the LEFT reseed, where prepending bases breaks forward nesting and forces_interval_rc's RC walk.)occis monotone non-increasing inL, so the first (largest)Lreachingmin_intvisL*.want_interval == falsereturns onlyL*(the driver'snext_pivotuse);truerecovers the exact interval by gallopingfind_boundaryout from the capped walk's interior seed —find_boundaryis seed-independent, so the boundaries (andocc) are byte-identical to a coldmem_search; the tight seed only removes the model launch.Byte-identity
Verified against an independent per-length
mem_searchoracle across reference-lifted queries andmin_intv ∈ {1,2,3,5,20,1e6}(covering the no-truncation, crossing, and no-qualifying-L→ zero paths), plus thewant_interval=falsespan-only return.Notes
shares_prefix/ref_less(nokeyed_compare_mask)._span_rc, it's an internal span primitive with no packed-pac guard (the caller's priormem_searchvalidates the pac); the guarded siblings are the public-FFI entrypoints, which this is not.pubwith no in-tree caller until thecollectreseed module lands (PR-D2) — the established stacked-primitive pattern; the proptest is its only current consumer./coderabbitai-review: 0 actionable findings.Summary by CodeRabbit
New Features
Bug Fixes / Robustness
Tests