Skip to content

Hw hash map solution#1699

Open
belkazavrik wants to merge 3 commits into
mate-academy:masterfrom
belkazavrik:hw-hashMap-solution
Open

Hw hash map solution#1699
belkazavrik wants to merge 3 commits into
mate-academy:masterfrom
belkazavrik:hw-hashMap-solution

Conversation

@belkazavrik

Copy link
Copy Markdown

No description provided.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

Changes are needed before this solution can be accepted, even though the core MyHashMap functionality (put, getValue, getSize, resizing, and load factor handling) is implemented correctly.
The first issue is a style/checklist violation: there is a blank line immediately after the class MyHashMap declaration, so the class body starts with an empty line; this breaks [CHECKLIST ITEM #1] (“Don't begin class or method implementation with empty line”) and should be fixed by simply deleting that leading empty line.
The second issue is ordering of members: the private inner Node class (around line 11) and private helper methods getIndex (around line 23), keysAreEqual (around line 27), and resize (around line 34) are declared before the public API methods; this conflicts with [CHECKLIST ITEM #5] (“Private methods and classes should be after public ones in your class”), so you should move the Node class and these helpers below put, getValue, and getSize.
Both of these are explicit checklist requirements, so they must be corrected for the submission to meet the task standards.
As a minor, optional improvement, you might also replace the literal 2 used in table.length * 2 during resize with a named constant (e.g., GROWTH_FACTOR) to make the resizing policy clearer.
Once you address the empty line and member ordering, your implementation will align well with both the functional and style requirements—you're very close, so 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example


public class MyHashMap<K, V> implements MyMap<K, V> {

private static final int DEFAULT_INITIAL_CAPACITY = 16;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist item #1: "Don't begin class or method implementation with empty line. Remove all redundant empty lines, be careful :)" There is an empty line at the start of the class body before the field declarations — remove it so the class/method implementations don't begin with a blank line.

Comment on lines +11 to +34
private static class Node<K, V> {
private final K key;
private V value;
private Node<K, V> next;

public Node(K key, V value, Node<K, V> next) {
this.key = key;
this.value = value;
this.next = next;
}
}

private int getIndex(K key, int length) {
return (key == null) ? 0 : Math.abs(key.hashCode() % length);
}

private boolean keysAreEqual(K key1, K key2) {
if (key1 == key2) {
return true;
}
return key1 != null && key1.equals(key2);
}

private void resize() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist item #5: "Private methods and classes should be after public ones in your class." The private inner Node class (line 11) and the private helper methods getIndex (line 23), keysAreEqual (line 27) and resize (line 34) are declared before the public API methods (put, getValue, getSize). Move private members below the public methods to follow the checklist guidance.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

Your solution is approved because your MyHashMap correctly implements put, getValue, and getSize, and it handles initial capacity, load factor, and resizing as required. The implementation respects the checklist: constants are used instead of magic numbers, Node<K,V> is properly parameterized and placed after the public API, and there are no remaining leading blank lines at the start of the class body or methods. The public/private modifiers are used appropriately, and helper methods are kept private and located after the public interface, which matches the style expectations. Functionally, the map correctly overwrites values for existing keys and resolves collisions using chaining. As a minor, non-blocking improvement, you could refine the bucket index calculation in put/getValue to avoid the rare Integer.MIN_VALUE edge case (for example, using key.hashCode() & 0x7fffffff before the modulo), but this is optional and not required for acceptance. Overall, this is a solid implementation that meets both the functional and checklist requirements—well done.


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

Footnotes

  1. Rate AI review example

package core.basesyntax;

public class MyHashMap<K, V> implements MyMap<K, V> {
private static final int DEFAULT_INITIAL_CAPACITY = 16;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates the checklist item exactly: "Don't begin class or method implementation with empty line. Remove all redundant empty lines, be careful :)" — there is an empty line immediately after the class declaration; remove that leading blank line so the class body starts without an empty line.

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