mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-24 10:33:34 +08:00
build
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user