Skip to content

Conversation

l1kcs
Copy link

@l1kcs l1kcs commented Jul 31, 2025

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Thanks for your hard work! 😊 Your MyHashMap implementation is almost perfect and meets most requirements, but there's a critical issue with how you calculate bucket indices: using Math.abs(hashCode % table.length) can still produce a negative index for Integer.MIN_VALUE, which may cause runtime errors. Please update your index calculation in all relevant methods (like put, getValue, and resize) to use a safer approach, such as (hashCode & 0x7FFFFFFF) % table.length, to guarantee non-negative indices. Once you fix this, your code will be ready to approve! Keep going, you're very close! 🚀


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines 34 to 35
int index = Math.abs(node.key == null ? 0 :
(int) (node.key.hashCode() % newTable.length));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: The index calculation for the new table during resizing can result in a negative value if hashCode() is negative. You should wrap the entire expression with Math.abs() to ensure the index is always non-negative, similar to how you do in the put() and getValue() methods. This is important for correct bucket placement after resizing.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Congratulations! 🎉 Your implementation of MyHashMap meets all the requirements and passes the review checklist. You have addressed all critical issues, especially the correct index calculation, and your code follows best practices and conventions. Great job—no further changes are needed! Keep up the excellent work! 🚀


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants