Added destructor function (#702)

* Added destructor function

* Fixed hash function

* Added hash_map_chaining.c file

* Amendment submission

* Delete hash_map_chaining.c

---------

Co-authored-by: Yudong Jin <krahets@163.com>
pull/704/head
XiaChuerwu 1 year ago committed by GitHub
parent 88a746f493
commit cf0d4b32ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -20,6 +20,16 @@ class HashMapChaining {
HashMapChaining() : size(0), capacity(4), loadThres(2.0 / 3), extendRatio(2) { HashMapChaining() : size(0), capacity(4), loadThres(2.0 / 3), extendRatio(2) {
buckets.resize(capacity); buckets.resize(capacity);
} }
/* 析构方法 */
~HashMapChaining() {
for (auto &bucket : buckets) {
for (Pair *pair : bucket) {
// 释放内存
delete pair;
}
}
}
/* 哈希函数 */ /* 哈希函数 */
int hashFunc(int key) { int hashFunc(int key) {

Loading…
Cancel
Save