Refactor calculateHashCode method for clarity#36325
Open
AgilAghamirzayev wants to merge 1 commit intospring-projects:mainfrom
Open
Refactor calculateHashCode method for clarity#36325AgilAghamirzayev wants to merge 1 commit intospring-projects:mainfrom
AgilAghamirzayev wants to merge 1 commit intospring-projects:mainfrom
Conversation
This will: 1. Mathematical Distribution (Collision Reduction) 2. Pipelining and CPU Caching 3. Avoiding "Method Heavy" Expressions Signed-off-by: Agil <41694337+AgilAghamirzayev@users.noreply.github.com>
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.
This will:
Mathematical Distribution (Collision Reduction)
Pipelining and CPU Caching
Avoiding "Method Heavy" Expressions
Mathematical Distribution (Collision Reduction)
In your original version, the multiplier 31 is only applied to the first element.
In the original, if field B changes by 1 and field C changes by -1, the hash remains exactly the same. When collisions happen, data structures like HashMap slow down significantly (shifting from O (1) to O(log n) or O(n) search time). By applying the multiplier at every step, you ensure that a small change in any field results in a massive change in the final hash.