Skip to content

Java02. ДЗ 01, Shevchenko Ilya#2

Open
Qwsafex wants to merge 3 commits into
masterfrom
MyHashMap
Open

Java02. ДЗ 01, Shevchenko Ilya#2
Qwsafex wants to merge 3 commits into
masterfrom
MyHashMap

Conversation

@Qwsafex

@Qwsafex Qwsafex commented Sep 20, 2016

Copy link
Copy Markdown
Owner

No description provided.

@sproshev sproshev 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.

Надо исправлять

Comment thread MyHashMap/settings.gradle
@@ -0,0 +1,2 @@
rootProject.name = 'MyHashMap'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

не все грэдловые файлы закоммичены

Comment thread MyHashMap/src/main/java/MyHashMap.java Outdated
MyLinkedList[] lists;

int keyCount;
int capacity;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

модификаторы доступа?

Comment thread MyHashMap/src/main/java/MyHashMap.java Outdated
}

public boolean contains(String key) {
MyLinkedList list = lists[key.hashCode() % capacity];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

вычисление индекса повторяется несколько раз, стоит выделить это в отдельный метод

Comment thread MyHashMap/src/main/java/MyHashMap.java Outdated
}
MyNode current = list.getHead();
while (current != null){
if (current.first.compareTo(key) == 0){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

equals?

Comment thread MyHashMap/src/main/java/MyHashMap.java Outdated
}

public String put(String key, String value) {
if(!contains(key)){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

можно обойтись без этого. по коду ниже -- keyCount нужно увеличить только в 1 случае

Comment thread MyHashMap/src/main/java/MyHashMap.java Outdated
if (current.first.compareTo(key) == 0){
list.remove(current);
if(list.empty()){
keyCount--;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

а если нет, то размер можно не уменьшать?)

}
assertEquals(0, hashMap.size());
//hashMap.remove(Integer.toString(3));
// assertEquals(5, hashMap.size());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

неважные комменты не должны попадать в репозиторий

assertNull(hashMap.remove("heh"));
for (int i = 0; i < 100; i++){
hashMap.put(Integer.toString(i), "heh");
hashMap.remove(Integer.toString(i));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

не проверено возвращаемое значение

assertEquals(0, hashMap.size());
}

} No newline at end of file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

баг с размером тоже должен быть протестирован

@Qwsafex

Qwsafex commented Dec 6, 2016

Copy link
Copy Markdown
Owner Author

@sproshev Поправил

@sproshev sproshev 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.

9.5, -0.5 за баг с размером

@@ -0,0 +1,29 @@
public class MyLinkedList {
private MyNode head;
public boolean empty() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

unused

@@ -0,0 +1,13 @@
public class MyNode {
public String first;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

final

@sproshev

Copy link
Copy Markdown

suggested changes

я промахнулся, менять что-либо необязательно

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