Skip to content

Feedback #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

Open
wants to merge 3 commits into
base: feedback
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

## 1. Информация о студенте

**Номер группы**: 00-000
**Номер группы**: 11-109

**Фамилия и Имя**: Иванов Иван
**Фамилия и Имя**: Салимов Радмир

## 2. Описание задания

Expand Down
25 changes: 18 additions & 7 deletions src/chaining_hash_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,20 @@ namespace assignment {
// 4. Увеличиваем кол-во ключей в словаре.
// 5. Если превышен коэффициент загрузки словаря, то расширяем словарь.

if (Contains(key)) {
return false;
}
// ... (ниже представлена часть реализации)

// вычисление индекса ячейки словаря по ключу
const int index = hash(key, buckets_.size());

// добавление пары "ключ-значение" в ячейку словаря (в конец связного списка)
buckets_[index].push_back(Node(key, value));

num_keys_++;
// расширение словаря до новой емкости в случае превышения коэффициента заполнения
if (num_keys_ / static_cast<double>(buckets_.size()) > load_factor_) {
const int new_capacity = 0 /* здесь должна быть ваше выражение */;
const int new_capacity = capacity() * kGrowthCoefficient;
resize(new_capacity);
}

Expand All @@ -58,7 +61,7 @@ namespace assignment {

std::optional<int> ChainingHashMap::Remove(int key) {

const int index = 0 /* напишите здесь свой код */;
const int index = hash(key, buckets_.size());

// здесь используется итератор (по сути указатель на узел списка)
for (auto it = buckets_[index].begin(); it != buckets_[index].end(); ++it) {
Expand All @@ -81,12 +84,14 @@ namespace assignment {
std::optional<int> ChainingHashMap::Search(int key) const {

// вычисление индекса ячейки для указанного ключа
const int index = 0 /* напишите здесь свой код */;
const int index = hash(key, buckets_.size());

// Проходимся по всем элемента в ячейке словаря.
// В худшем случае все элементы попали в одну ячейку словаря и сложность поиска ~ O(N).
for (const Node& node : buckets_[index]) {
// напишите здесь свой код ...
if (node.key == key) {
return node.value;
}
}

return std::nullopt;
Expand All @@ -104,7 +109,13 @@ namespace assignment {
}

bool ChainingHashMap::Contains(int key) const {
// Напишите здесь свой код ...
int index = hash(key, buckets_.size());
const Bucket& bucket = buckets_[index];
for (const Node& node : bucket) {
if (node.key == key) {
return true;
}
}
return false;
}

Expand Down Expand Up @@ -133,7 +144,7 @@ namespace assignment {
// пересчитываем индексы элементов словаря, учитывая новую емкость
for (const Bucket& bucket : buckets_) {
for (const Node& node : bucket) {
const int new_index = 0 /* напишите здесь свой код */;
const int new_index = hash(node.key, buckets_.size());
new_buckets[new_index].push_back(node);
}
}
Expand Down