-
Notifications
You must be signed in to change notification settings - Fork 14
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
Java01. ДЗ 2, Кравцун Андрей, подгруппа 2 #17
base: 02-dict
Are you sure you want to change the base?
Conversation
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 oldValue; | ||
} | ||
} | ||
} |
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.
внутренние и вложенные классы должны располагаться внизу
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.
@sproshev Т.е. по java code conventions приватные поля должны располагаться вверху, а приватные вложенные и внутренние классы внизу?
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.
структура, которая была представлена на практике, позволяет быстрее понимать класс:
- заходим, видим поля -- то, на чем класс базируется
- конструктор -- то, как создаются экземпляры класса
- публичные методы -- то, как пользоваться классом
- приватные методы -- то, как класс реализован
- внутренние и вложенные класс -- то, что помогает классу
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 int hashCodeBucketIndex(String key) { | ||
return bucketIndex(key, buckets.length); | ||
} |
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.
приватные методы идут после публичных
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.
можно ли этот метод тоже назвать bucketIndex?
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 есть перегрузка? Это новость, честно говоря.
Исправил.
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.
есть
fullSize = 0; | ||
} | ||
|
||
private int bucketIndex(String key, int bucketsNumber) { |
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.
статик
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.
Исправил.
} | ||
|
||
public String put(String key, String value) { | ||
// String gotValue = get(key); |
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.
неиспользуемый код надо удалять
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.
Исправил.
public String put(String key, String value) { | ||
// String gotValue = get(key); | ||
int hashIndex = hashCodeBucketIndex(key); | ||
Bucket bucket = buckets[hashIndex]; // reference or copied 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.
а какие аргументы за тот или иной вариант?
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, Python), я полагаюсь на юнит-тесты. Есть где-то четкие правила?
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.
а есть ли в джаве такое понятие, как конструктор копирования?
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.
Вопрос выглядит риторическим - скорее всего, нет.
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.
Верно, поэтому и копирования никакого не происходит
trueSize = 0; | ||
} | ||
|
||
public int index(String key) { |
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.
приватный
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.
Исправил.
} | ||
} | ||
|
||
public boolean isFull() { |
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.
приватный
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.
Исправил.
} | ||
fullSize--; | ||
trueSize--; | ||
values[trueSize] = Node.empty(); |
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.
= 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.
исправил.
assertTrue(d.size() == size); | ||
} | ||
} | ||
assertTrue(d.size() == size); |
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.
assertEquals и в других местах
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.
Исправил.
} else { | ||
keys.add(key); | ||
values.add(value); | ||
assertEquals(d.put(key, value), 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.
assertNull
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.
Исправил.
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.
10
return bucketIndex(key, buckets.length); | ||
} | ||
|
||
private Bucket[] emptyBuckets(int newBucketsNumber) { |
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.
static
|
||
public String put(String key, String value) { | ||
int i = index(key); | ||
assert (canPut(key)); |
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.
assert'ы работают только с флагом -ea, он обычно автоматически подставляется в тестах и дебаге, в остальное время assert'ы отключены
Проверяющий: Семен Прошев. @sproshev