Skip to content

Conversation

@DmKazakov
Copy link
Owner

No description provided.

Copy link
Collaborator

@yurii-litvinov yurii-litvinov left a 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
Copy link
Collaborator

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);
Copy link
Collaborator

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();
Copy link
Collaborator

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);
Copy link
Collaborator

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) {
Copy link
Collaborator

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;
Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Тесты лучше в отдельную папку на одном уровне с src, иначе системы сборки их не найдут

Copy link
Collaborator

@yurii-litvinov yurii-litvinov left a 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 {
Copy link
Collaborator

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;
Copy link
Collaborator

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
Copy link
Collaborator

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();
Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Обычно тесты в том же пакете, что и тестируемый класс, чтобы иметь доступ к его пакетным методам

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.

3 participants