-
Notifications
You must be signed in to change notification settings - Fork 0
Hashtable #1
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?
Conversation
yurii-litvinov
left a comment
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.
По тестам и комментариям существенных замечаний нет, саму хеш-таблицу можно улучшить (немного, правда, она и так почти ок)
| } | ||
|
|
||
| /** | ||
| * @return number of keys in hashtable |
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.
Лучше без тэга @return --- так этот комментарий сгенерится только в детальное описание метода, а если без тэга, то и в краткое описание. Как сейчас, краткое описание будет пустым
| */ | ||
| public String put(String key, String value) { | ||
| int hash = Math.floorMod(key.hashCode(), capacity); | ||
| String return_value = hashtable[hash].put(key, 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.
В Java принят стиль camelCase для именования переменных, так что по джавовскому стайлгайду правильно returnType
| */ | ||
| public void clear() { | ||
| for (int i = 0; i < capacity; i++) | ||
| hashtable[i] = new LinkedList(); |
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.
Лучше заключать в фигурные скобки тело, даже если там один оператор. Во избежание ошибок вида
for (int i = 0; i < capacity; i++)
System.out.println(i);
hashtable[i] = new LinkedList();| * Singly linked list for hashtable. | ||
| */ | ||
| public class LinkedList { | ||
| Node head = new Node(null, 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.
Если не указывать модификатор видимости, видимость будет пакетная. Что, наверное, для головы списка не очень :)
| /** | ||
| * Adds new node to list, increments size. | ||
| */ | ||
| private void add(Node new_node) { |
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.
Тут тоже, лучше newNode
| */ | ||
| class Node { | ||
| Node next; | ||
| String key, 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.
Тут тоже с видимостью полей всё плохо
| @@ -0,0 +1,155 @@ | |||
| package ru.spbau.mit.kazakov.HashTable.test; | |||
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.
Тесты лучше в отдельную папку на одном уровне с src, иначе системы сборки их не найдут
yurii-litvinov
left a comment
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.
Существенных замечаний больше нет, зачтена полностью
| * Node for linked list. | ||
| * Store hashtable's key and value | ||
| */ | ||
| class Node { |
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.
он должен бы быть private static
| */ | ||
| class Node { | ||
| private Node next; | ||
| private String key, 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.
Лучше каждое поле объявлять отдельно. Вот, например, key по смыслу final (менять ключ в записи в хеш-таблице --- очень плохая идея), а value --- нет. В такой форме записи это не записать.
| /** | ||
| * Node constructor | ||
| * | ||
| * @param key key in hash table |
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.
Лучше не выравнивать по вертикали, это первого же рефакторинга не переживёт
| class HashTableTest { | ||
| @Test | ||
| void testConstructor() { | ||
| HashTable hashtable = new HashTable(); |
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.
Переменная в этом тесте не нужна, достаточно просто вызвать конструктор и посмотреть, что он не падает
| @@ -0,0 +1,153 @@ | |||
| import org.junit.jupiter.api.Test; | |||
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.
Обычно тесты в том же пакете, что и тестируемый класс, чтобы иметь доступ к его пакетным методам
No description provided.