Finish README task#1697
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved as part of an educational override so you can continue progressing while you practice the remaining style details. Functionally, your MyHashMap looks solid: put, getValue, getSize, initial capacity, load factor, and resize logic are all implemented correctly, and your inner Entry<K, V> class is properly parameterized and kept simple without getters/setters. One point to improve is the use of generics: in your put method where you create new entries (e.g., new Entry<K, V>(key, value)), you should prefer the diamond operator new Entry<>(key, value) to reduce verbosity and follow the generics guideline [CHECKLIST ITEM #8]. Another stylistic issue is in your resize() method, where you double the capacity using a hardcoded 2 (e.g., capacity *= 2;); this should be extracted into a named constant like RESIZE_FACTOR to avoid magic numbers and make the intent clearer [CHECKLIST ITEM #2]. These are not functional bugs, but addressing them will make your code more maintainable and closer to production-quality standards. Overall, you did well on the core logic and structure of the hash map; tightening up these small style points will further improve your code quality.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| if (size >= threshold) { | ||
| table = resize(); | ||
| } | ||
| Entry<K, V> toPut = new Entry<K, V>(key, value); |
There was a problem hiding this comment.
"Diamond operator\nBe attentive with the diamond operator in java. \nWhat is the difference between: new Node<>(...) and new Node<K,V>(...)and new Node(...). Read more about it" — You're instantiating the entry with explicit type arguments: new Entry<K, V>(key, value) (line shows this). Consider using the diamond operator: new Entry<>(key, value) to avoid redundancy and follow the checklist guidance.
|
|
||
| private Entry<K, V>[] resize() { | ||
| size = 0; | ||
| capacity *= 2; |
There was a problem hiding this comment.
"Any magic numbers should be constants\nYour code should be easy to read. Move all hardcoded values to constant fields and give them informative names. For example: constants can be defaultCapacity, loadFactor..." — In resize() you use the literal 2 to double capacity (capacity *= 2;). Consider extracting this as a named constant (for example GROWTH_FACTOR or RESIZE_MULTIPLIER) to satisfy the magic-number guideline.
No description provided.