This commit is contained in:
krahets
2023-04-16 04:55:51 +08:00
parent 72a8318c75
commit dede472c45
5 changed files with 654 additions and 21 deletions

View File

@@ -536,6 +536,14 @@ $$
buckets = vector<Entry *>(100);
}
~ArrayHashMap() {
// 释放内存
for (const auto &bucket : buckets) {
delete bucket;
}
buckets.clear();
}
/* 哈希函数 */
int hashFunc(int key) {
int index = key % 100;
@@ -561,7 +569,8 @@ $$
/* 删除操作 */
void remove(int key) {
int index = hashFunc(key);
// 置为 nullptr ,代表删除
// 释放内存并置为 nullptr
delete buckets[index];
buckets[index] = nullptr;
}