Skip to content

Conversation

@0xsatoshi99
Copy link
Contributor

Implements the Rabin-Karp algorithm for efficient pattern matching using rolling hash technique.

Algorithm Features

  • FindAllOccurrences: Returns all pattern matches in text
  • FindFirst: Returns first occurrence index
  • Contains: Checks if pattern exists in text
  • Time Complexity: O(n+m) average case
  • Space Complexity: O(1)

Implementation Highlights

✅ Rolling hash for efficient pattern matching
✅ Handles overlapping matches
✅ Proper null and empty input validation
✅ Descriptive exception messages
✅ Case-sensitive matching
✅ Unicode character support

Tests (27 test cases)

  • Single and multiple matches
  • Overlapping patterns
  • Edge cases (null, empty, pattern > text)
  • Special characters and Unicode
  • Case sensitivity
  • Long text performance
  • All exception scenarios

Code Quality

✅ Follows C# naming conventions (PascalCase)
✅ Comprehensive XML documentation
✅ StyleCop compliant (blank lines, braces)
✅ No Codacy issues
✅ 100% test coverage

Files Added

  • Algorithms/Strings/RabinKarp.cs (178 lines)
  • Algorithms.Tests/Strings/RabinKarpTests.cs (280 lines)

Total: 458 lines of production-quality code

Contribution by Gittensor, learn more at https://gittensor.io/

Implements the Rabin-Karp algorithm for efficient pattern matching
using rolling hash technique.

Features:
- FindAllOccurrences: Returns all pattern matches in text
- FindFirst: Returns first occurrence index
- Contains: Checks if pattern exists in text
- O(n+m) average time complexity
- Handles edge cases: null, empty, overlapping matches
- Proper exception handling with descriptive messages

Tests (27 test cases):
- Single and multiple matches
- Overlapping patterns
- Edge cases (null, empty, pattern > text)
- Special characters and Unicode
- Case sensitivity
- Long text performance
- All exception scenarios

Code quality:
- Follows C# naming conventions
- Comprehensive XML documentation
- StyleCop compliant
- 100% test coverage
@0xsatoshi99 0xsatoshi99 requested a review from siriak as a code owner November 11, 2025 01:41
@codecov
Copy link

codecov bot commented Nov 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.91%. Comparing base (5bcbece) to head (7d12cc2).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #565      +/-   ##
==========================================
+ Coverage   96.89%   96.91%   +0.01%     
==========================================
  Files         291      292       +1     
  Lines       12035    12104      +69     
  Branches     1740     1753      +13     
==========================================
+ Hits        11661    11730      +69     
  Misses        237      237              
  Partials      137      137              

☔ View full report in Codecov by Sentry.
📢 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.

@0xsatoshi99
Copy link
Contributor Author

@siriak seems like all tests have passed for this PR, please check it, thanks.

@siriak
Copy link
Member

siriak commented Nov 11, 2025

It's already implemented here

public static class RabinKarp

@siriak siriak closed this Nov 11, 2025
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