Conversation
sproshev
suggested changes
Sep 27, 2016
| @@ -0,0 +1,2 @@ | |||
| rootProject.name = 'MyHashMap' | |||
|
|
|||
| MyLinkedList[] lists; | ||
|
|
||
| int keyCount; | ||
| int capacity; |
| } | ||
|
|
||
| public boolean contains(String key) { | ||
| MyLinkedList list = lists[key.hashCode() % capacity]; |
There was a problem hiding this comment.
вычисление индекса повторяется несколько раз, стоит выделить это в отдельный метод
| } | ||
| MyNode current = list.getHead(); | ||
| while (current != null){ | ||
| if (current.first.compareTo(key) == 0){ |
| } | ||
|
|
||
| public String put(String key, String value) { | ||
| if(!contains(key)){ |
There was a problem hiding this comment.
можно обойтись без этого. по коду ниже -- keyCount нужно увеличить только в 1 случае
| if (current.first.compareTo(key) == 0){ | ||
| list.remove(current); | ||
| if(list.empty()){ | ||
| keyCount--; |
There was a problem hiding this comment.
а если нет, то размер можно не уменьшать?)
| } | ||
| assertEquals(0, hashMap.size()); | ||
| //hashMap.remove(Integer.toString(3)); | ||
| // assertEquals(5, hashMap.size()); |
There was a problem hiding this comment.
неважные комменты не должны попадать в репозиторий
| assertNull(hashMap.remove("heh")); | ||
| for (int i = 0; i < 100; i++){ | ||
| hashMap.put(Integer.toString(i), "heh"); | ||
| hashMap.remove(Integer.toString(i)); |
| assertEquals(0, hashMap.size()); | ||
| } | ||
|
|
||
| } No newline at end of file |
There was a problem hiding this comment.
баг с размером тоже должен быть протестирован
Owner
Author
|
@sproshev Поправил |
sproshev
suggested changes
Dec 17, 2016
| @@ -0,0 +1,29 @@ | |||
| public class MyLinkedList { | |||
| private MyNode head; | |||
| public boolean empty() { | |||
| @@ -0,0 +1,13 @@ | |||
| public class MyNode { | |||
| public String first; | |||
я промахнулся, менять что-либо необязательно |
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.
No description provided.