Skip to content

fix(strings): use case-insensitive shift table in HorspoolSearch.findFirstInsensitive - #7663

Merged
alxkm merged 2 commits into
TheAlgorithms:masterfrom
Rishavbhattarai:fix/horspool-case-insensitive-shift
Oct 27, 2026
Merged

alxkm merged 2 commits into
TheAlgorithms:masterfrom
Rishavbhattarai:fix/horspool-case-insensitive-shift

Conversation

@Rishavbhattarai

Copy link
Copy Markdown
Contributor

HorspoolSearch.findFirstInsensitive compares characters without case, but it builds and reads the bad-character shift table with case. When the text has a different case from the pattern, a shift can jump over a real match:

HorspoolSearch.findFirstInsensitive("AB", "xab"); // -1, expected 1
HorspoolSearch.findFirstInsensitive("ba", "bbBA"); // -1, expected 2

The fix lower-cases the table keys and the looked-up text character in case-insensitive mode. Case-sensitive search does not change.

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations. (No new algorithm.)
  • All new algorithms include a corresponding test class that validates their functionality. (Regression test added.)
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

@codecov-commenter

codecov-commenter commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.21%. Comparing base (bd64e8d) to head (77e7eed).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7663      +/-   ##
============================================
- Coverage     82.22%   82.21%   -0.01%     
- Complexity     8399     8401       +2     
============================================
  Files           843      843              
  Lines         26140    26141       +1     
  Branches       5098     5100       +2     
============================================
- Hits          21494    21493       -1     
- Misses         3853     3854       +1     
- Partials        793      794       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rishavbhattarai
Rishavbhattarai marked this pull request as ready for review October 27, 2026 03:09

@alxkm alxkm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you for the contribution.

@alxkm
alxkm merged commit a7a2441 into TheAlgorithms:master Oct 27, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants