Open
Conversation
ay2306
requested changes
Oct 14, 2020
Collaborator
There was a problem hiding this comment.
Create an issue and use proper PR template.
And
Code is very not read-friendly and non-preferable to be used actually in some implementation.
Some advice
- Use hashing on
unsigned long longfor hashing to preventing overflow issue and handling negatives - Encapsulate your code with each method clearly defining what are they doing
- Use the correct access scope.
- Avoid using
powas it convertsdoubleand casting it to an integer might not be the best choice. - Write clean code and use proper variable names
|
|
||
| ll result = 0; | ||
| for (int i=0; i<len; i++) { | ||
| result += (ll)text[i]*(ll)pow(prime,i); |
Collaborator
There was a problem hiding this comment.
Overflow issue will be there
| ll reCalculateHash (string str, int oldIndex, int newIndex, ll oldHash, int patLen, ll prime) { | ||
| ll newhash = oldHash - str[oldIndex]; | ||
| newhash=newhash/prime; | ||
| newhash+= (ll)str[newIndex]*(ll)pow(prime, patLen-1); |
Collaborator
There was a problem hiding this comment.
overflow issue will be there
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.
Added pattern match algorithm
New Algorithm
I have squashed my commits
I have commented my code, particularly in hard-to-understand areas
I have made corresponding changes to the documentation
My code is a working bug-free code