feat: modified implementation of the Manacher algorithm#911
Closed
oulaindex wants to merge 3 commits into
Closed
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #911 +/- ##
==========================================
+ Coverage 95.32% 95.36% +0.04%
==========================================
Files 319 319
Lines 20807 20802 -5
==========================================
+ Hits 19834 19838 +4
+ Misses 973 964 -9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
Please ping one of the maintainers once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to ask for help in our Gitter channel. Thank you for your contributions! |
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.
Description
This pull request updates the implementation of the Manacher algorithm for finding the longest palindromic substring.
Summary of changes:
manacher.rscontains a critical logic bug:if right_from_current_center > i && i > current_center,which is never true when both variables are zero at initialization.
As a result, the logic for updating current_center and right_from_current_center can never execute inside the conditional block at the start, causing these variables to remain unchanged at zero during the initial iterations. Although the final result remains correct due to redundant expansions, this leads to unnecessary repeated checks and significantly reduces the efficiency of the algorithm.
manacher.rs) fixes this by:Type of change
Checklist:
cargo clippy --all -- -D warningsjust before my last commit and fixed any issue that was found.cargo fmtjust before my last commit.cargo testjust before my last commit and all tests passed.Note:
This PR not only clarifies and streamlines the code, but, most importantly, it fixes a functional bug in the center and boundary assignment logic.
All tests pass, and the implementation follows the best practices and guidelines for Manacher’s algorithm.