Repository navigation
Keep the prefix penalty capped when a later copy replaces the first letter - #113
Merged
Merged
Conversation
…etter [patch] The prefix refund and capped prefix penalty ran only when the first pattern letter first matched. A later, better-placed copy of that letter could replace it as the best letter, making everything before it prefix, yet those codepoints stayed charged one point each with no cap, plus a point for the superseded letter. "a" + N x "_ab" scored 13 - N for "ab". Track what was charged while the first letter is still provisional, and when a copy replaces it, refund that and charge the capped prefix penalty for the new position instead. Fixes #94 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Vpup29Ycn8SGi7LvBjAq1c
|
This was referenced Oct 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #94
What changed
In
CalculateScoreCore, the prefix refund and the cappedPenalizeNonPatternCharacterscall ran only once, at the first provisional match of the first pattern letter. A later copy of that letter could still replace it as the best letter, for example a copy that earns the separator bonus. When that happened, everything before the copy became prefix, but those codepoints had already been chargedunmatchedLetterPenaltyeach with no cap, plus −1 for the superseded letter. The result was that"a" + N×"x" + "_ab"scored13 − Nfor"ab".While the best letter is still the uncommitted first pattern codepoint, the method now records two things:
When a copy of that letter replaces it, both are refunded, the capped prefix penalty is charged again for the new position, and the superseded letter is not charged −1. The provisional state ends as soon as the first letter is committed, when the next pattern codepoint matches or a pattern repeat arrives. From then on nothing changes.
The new condition is in a small helper,
ReplacesProvisionalFirstLetter, which keepsCalculateScoreCoreunder the CA1502 complexity limit.Tests
CalculateScore_ReplacedFirstLetter_KeepsThePrefixPenaltyCapped(N = 5, 20, 100):"a" + x + "_ab"now scores the same asx + "_ab".Score_StrayEarlyFirstLetter_DoesNotSinkAPathMatch:tools/build/scripts/unit_testanddocs/build/scripts/unit_testnow score the same for"test".Results:
Fuzzy.cschange reverted, all 4 new cases fail.ReadmeTests. The library builds on all its targets.Scope
The triage notes that #89, #91 and #94 all touch the rematch and prefix accounting. #91 is already on
main, and this fix sits on top of it with the existing ranking tests still passing. Related open issues #101 (rematch keeping +5 adjacency) and #112 (an early partial match locking the alignment) are separate behaviours in the same loop, and this PR deliberately leaves them alone.🤖 Generated with Claude Code
https://claude.ai/code/session_01Vpup29Ycn8SGi7LvBjAq1c
Generated by Claude Code