Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Hashmap#2

Open
domwst wants to merge 5 commits intomasterfrom
hashmap
Open

Hashmap#2
domwst wants to merge 5 commits intomasterfrom
hashmap

Conversation

@domwst
Copy link
Owner

@domwst domwst commented Feb 13, 2020

Шатов Олег БПМИ193-2
Id посылки: 30815628

Copy link
Collaborator

@ifsmirnov ifsmirnov left a comment

Choose a reason for hiding this comment

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

Стоит избавиться от однобуквенных переменных и лишних сокращений, в остальном неплохо.

hashmap.h Outdated
template<class KeyType, class ValueType, class Hash = std::hash<KeyType>>
class HashMap {
private:
static const size_t sizes[];
Copy link
Collaborator

Choose a reason for hiding this comment

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

constexpr, и можно будет объявить прямо здесь.

hashmap.h Outdated
std::vector<std::forward_list<std::pair<const KeyType, ValueType>>> buckets;
Hash hasher;

void change_size(size_t new_sz) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

new_size, не надо сокращать на ровном месте.

hashmap.h Outdated
if (new_sz == cur_len) {
return;
}
new_sz = sizes[cur_len = new_sz];
Copy link
Collaborator

Choose a reason for hiding this comment

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

То, что язык позволяет что-то сделать, не повод так реально писать :)

hashmap.h Outdated
private:
static const size_t sizes[];

size_t cur_size = 0, cur_len = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Непонятно, чем size отличается от len. Возможно, имелись в виду size и capacity?

hashmap.h Outdated
private:
static const size_t sizes[];

size_t cur_size = 0, cur_len = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Непонятно, чем size отличается от len. Возможно, имелись в виду size и capacity?

hashmap.h Outdated
return y;
}
}
buckets[h].push_front({key, ValueType()});
Copy link
Collaborator

Choose a reason for hiding this comment

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

emplace_front

hashmap.h Outdated
}

void clear() {
for (auto &b : buckets) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

auto& bucket, сокращение не нужно.

hashmap.h Outdated

public:
const_iterator() {}
const_iterator(const HashMap &mp) : cur(mp.buckets.begin()), end(mp.buckets.end()), biter(cur->begin()) {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

const hashMap& hashMap

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

Choose a reason for hiding this comment

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

bucketIter (и снова хочется сделать using, про который я писал выше).

return end();
}

iterator find(const KeyType &val) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Давай попробуем избавиться от такого дублирования между find и find count.

@domwst
Copy link
Owner Author

domwst commented Mar 31, 2020

Все исправил

@domwst domwst self-assigned this Nov 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants