Skip to content

fix(searches): support characters outside extended ASCII in BoyerMoore - #7664

Open
Rishavbhattarai wants to merge 1 commit into
TheAlgorithms:masterfrom
Rishavbhattarai:fix/boyermoore-non-ascii
Open

Rishavbhattarai wants to merge 1 commit into
TheAlgorithms:masterfrom
Rishavbhattarai:fix/boyermoore-non-ascii

Conversation

@Rishavbhattarai

Copy link
Copy Markdown
Contributor

BoyerMoore keeps its bad-character table in a 256-entry array indexed by char, so any character above 255 throws, in the text or in the pattern:

BoyerMoore.staticSearch("x中文", "中"); // ArrayIndexOutOfBoundsException: Index 20013 out of bounds for length 256

The fix stores the table in a HashMap<Character, Integer> and reads missing characters as -1, which is what the array was filled with. The search loop 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

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.18%. Comparing base (96ed2d7) to head (741fcc1).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #7664      +/-   ##
============================================
- Coverage     82.20%   82.18%   -0.02%     
+ Complexity     8397     8394       -3     
============================================
  Files           843      843              
  Lines         26133    26130       -3     
  Branches       5097     5096       -1     
============================================
- Hits          21482    21476       -6     
- Misses         3859     3860       +1     
- Partials        792      794       +2     

☔ 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
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.

2 participants