-
Notifications
You must be signed in to change notification settings - Fork 1.5k
my hash map #1584
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
base: master
Are you sure you want to change the base?
my hash map #1584
Conversation
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.
Review Summary
Thank you for your hard work! Before your PR can be approved, please address the following critical issues:
- In
MyHashMap.java
, the constructor does not initialize thetable
orthreshold
, which can cause runtime errors. Theresize
method also doesn't update the threshold correctly, and theput
method incrementssize
even when updating existing keys. - In
Bus.java
, thehashCode()
method does not handle possible null values formodel
orcolor
, which can lead toNullPointerException
.
Please fix these issues so your code meets the core requirements. You're almost there—keep going! 🚀
✨ 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
|
||
private Node<K, V>[] table; | ||
|
||
public MyHashMap() { |
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.
Issue: The constructor does not initialize the table or threshold. According to the checklist, the initial capacity and threshold should be set up in the constructor. Consider initializing the table and threshold here.
tableLength = (tab = resize()).length; | ||
} | ||
if ((nodeAtPosition = tab[pointer = (hash & tableLength - 1)]) == null) { | ||
tab[pointer] = new Node<>(key, value, hash, null); |
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.
Issue: In the put
method, size
is incremented regardless of whether a new key is added or an existing key is updated. According to the checklist, the size should only increase when a new key-value pair is added, not when updating an existing key.
} | ||
} | ||
if (++size > threshold) { | ||
resize(); |
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.
Issue: The resize
method is called after incrementing size, but the threshold may not be set correctly if the table was not initialized in the constructor. Ensure threshold is always set appropriately after resizing or initialization.
public int hashCode() { | ||
return 0; | ||
int result = 31; | ||
result = 17 * result + model.hashCode(); |
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.
Issue: The hashCode()
method does not handle the case where model
is null. According to the checklist, you should handle possible null values for fields in hashCode()
.
return 0; | ||
int result = 31; | ||
result = 17 * result + model.hashCode(); | ||
result = 17 * result + color.hashCode(); |
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.
Issue: The hashCode()
method does not handle the case where color
is null. According to the checklist, you should handle possible null values for fields in hashCode()
.
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.
Review Summary
Thank you for your hard work! 😊 Your implementation is almost complete, but there is one critical issue left: in your MyHashMap
, the put
method increments size
even when updating an existing key. According to the requirements, size
should only increase when a new key-value pair is added. Please adjust your logic so that size
is only incremented for new keys. Once you fix this, your code will fully meet the task requirements! Keep it up! 🚀
✨ 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
if (++size > threshold) { | ||
resize(); | ||
} |
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.
Issue: The size
variable is incremented every time put
is called, even when updating an existing key. According to the checklist, size should only be incremented when a new key-value pair is added, not when updating an existing key. Please adjust the logic so that size
is only incremented when a new node is actually inserted.
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.
if (existingMapping != null) {
existingMapping.setValue(value);
return;
}
I have here return, which prevent changing size within updating value
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.
привіт, твій блок коду виконується не в тій гілці до якої є зауваження, тобто потенційно проблема яку зазначив ШІ може виникати
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.
Review Summary
Great work! 🚀 Your implementation of MyHashMap
now fully meets all the requirements and best practices outlined in the task. The critical issue with the size
incrementation has been resolved, and your code is clean, well-structured, and easy to maintain. All necessary methods are present, constants are used appropriately, and your classes are well-parameterized and follow Java conventions. There are no missing functionalities or unnecessary files. No further changes are required—your code is ready for submission! Keep up the excellent work and continue applying these best practices in future projects.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.