-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: let KMP algorithm return index #2713
Conversation
If you have the time could you write tests for this algorithm? |
Hi, I've added some test cases! Additionally, I've changed the return value to the starting index of the pattern. Perhaps the usage of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much! Great work, Feel free to add yourself as one of the authors in the file header comment
I don't understand: #ifdef _MSC_VER
#include <string> // use this for MS Visual C++
#else
#include <cstring>
#endif |
Why not just use |
It's old code feel free to remove |
Thanks. I have deleted it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contributions! Happy to have this algorithm refactored! ❤️
Description of Change
For
strings/knuth_morris_pratt.cpp
:fix: if
pattern
is empty, it should immediately return, otherwisepattern[k]
will access out of bounds.feat: let the KMP algorithm return index and add more tests.
Checklist
Notes: