Skip to content

feat: optimize multi-pattern search using Aho–Corasick algorithm#157

Merged
Samarth2190 merged 1 commit intoSamarth2190:mainfrom
mNik033:feat/aho-corasick-optimization
Oct 31, 2025
Merged

feat: optimize multi-pattern search using Aho–Corasick algorithm#157
Samarth2190 merged 1 commit intoSamarth2190:mainfrom
mNik033:feat/aho-corasick-optimization

Conversation

@mNik033
Copy link
Copy Markdown
Contributor

@mNik033 mNik033 commented Oct 30, 2025

Replace the Rabin–Karp–based implementation in checkMultiplePatterns with an Aho–Corasick automaton for efficient simultaneous pattern matching.

This reduces the time complexity from O(p·n) to O(Σm + n + matches), where p is the number of patterns, n is the length of the text, and Σm is the total length of all patterns.

The new approach eliminates redundant re-scans of the text and significantly improves performance for large pattern sets.

Replace the Rabin–Karp–based implementation in checkMultiplePatterns
with an Aho–Corasick automaton for efficient simultaneous pattern matching.

This reduces the time complexity from O(p·n) to O(Σm + n + matches),
where p is the number of patterns, n is the length of the text, and Σm is the total length
of all patterns.

The new approach eliminates redundant re-scans of the text and
significantly improves performance for large pattern sets.
@mNik033
Copy link
Copy Markdown
Contributor Author

mNik033 commented Oct 31, 2025

@Samarth2190 Hi, could you please review this PR?

@Samarth2190
Copy link
Copy Markdown
Owner

Great implementation. Noted a few minor code quality improvements which are non-blocking and can be fixed in future iterations.
Merging PR.

@Samarth2190 Samarth2190 merged commit 24a7033 into Samarth2190:main Oct 31, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants