Conversation
ifsmirnov
left a comment
There was a problem hiding this comment.
Стоит избавиться от однобуквенных переменных и лишних сокращений, в остальном неплохо.
hashmap.h
Outdated
| template<class KeyType, class ValueType, class Hash = std::hash<KeyType>> | ||
| class HashMap { | ||
| private: | ||
| static const size_t sizes[]; |
There was a problem hiding this comment.
constexpr, и можно будет объявить прямо здесь.
hashmap.h
Outdated
| std::vector<std::forward_list<std::pair<const KeyType, ValueType>>> buckets; | ||
| Hash hasher; | ||
|
|
||
| void change_size(size_t new_sz) { |
There was a problem hiding this comment.
new_size, не надо сокращать на ровном месте.
hashmap.h
Outdated
| if (new_sz == cur_len) { | ||
| return; | ||
| } | ||
| new_sz = sizes[cur_len = new_sz]; |
There was a problem hiding this comment.
То, что язык позволяет что-то сделать, не повод так реально писать :)
hashmap.h
Outdated
| private: | ||
| static const size_t sizes[]; | ||
|
|
||
| size_t cur_size = 0, cur_len = 0; |
There was a problem hiding this comment.
Непонятно, чем size отличается от len. Возможно, имелись в виду size и capacity?
hashmap.h
Outdated
| private: | ||
| static const size_t sizes[]; | ||
|
|
||
| size_t cur_size = 0, cur_len = 0; |
There was a problem hiding this comment.
Непонятно, чем size отличается от len. Возможно, имелись в виду size и capacity?
hashmap.h
Outdated
| return y; | ||
| } | ||
| } | ||
| buckets[h].push_front({key, ValueType()}); |
hashmap.h
Outdated
| } | ||
|
|
||
| void clear() { | ||
| for (auto &b : buckets) { |
There was a problem hiding this comment.
auto& bucket, сокращение не нужно.
hashmap.h
Outdated
|
|
||
| public: | ||
| const_iterator() {} | ||
| const_iterator(const HashMap &mp) : cur(mp.buckets.begin()), end(mp.buckets.end()), biter(cur->begin()) {} |
hashmap.h
Outdated
| friend HashMap; | ||
| private: | ||
| typename std::vector<std::forward_list<std::pair<const KeyType, ValueType>>>::const_iterator cur, end; | ||
| typename std::forward_list<std::pair<const KeyType, ValueType>>::const_iterator biter; |
There was a problem hiding this comment.
bucketIter (и снова хочется сделать using, про который я писал выше).
| return end(); | ||
| } | ||
|
|
||
| iterator find(const KeyType &val) { |
There was a problem hiding this comment.
Давай попробуем избавиться от такого дублирования между find и find count.
|
Все исправил |
Шатов Олег БПМИ193-2
Id посылки: 30815628