|
|
@ -32,7 +32,7 @@ HashMapOpenAddressing *newHashMapOpenAddressing() {
|
|
|
|
hashMap->capacity = 4;
|
|
|
|
hashMap->capacity = 4;
|
|
|
|
hashMap->loadThres = 2.0 / 3.0;
|
|
|
|
hashMap->loadThres = 2.0 / 3.0;
|
|
|
|
hashMap->extendRatio = 2;
|
|
|
|
hashMap->extendRatio = 2;
|
|
|
|
hashMap->buckets = (Pair **)malloc(sizeof(Pair *) * hashMap->capacity);
|
|
|
|
hashMap->buckets = (Pair **)calloc(hashMap->capacity, sizeof(Pair *));
|
|
|
|
hashMap->TOMBSTONE = (Pair *)malloc(sizeof(Pair));
|
|
|
|
hashMap->TOMBSTONE = (Pair *)malloc(sizeof(Pair));
|
|
|
|
hashMap->TOMBSTONE->key = -1;
|
|
|
|
hashMap->TOMBSTONE->key = -1;
|
|
|
|
hashMap->TOMBSTONE->val = "-1";
|
|
|
|
hashMap->TOMBSTONE->val = "-1";
|
|
|
@ -151,7 +151,7 @@ void extend(HashMapOpenAddressing *hashMap) {
|
|
|
|
int oldCapacity = hashMap->capacity;
|
|
|
|
int oldCapacity = hashMap->capacity;
|
|
|
|
// 初始化扩容后的新哈希表
|
|
|
|
// 初始化扩容后的新哈希表
|
|
|
|
hashMap->capacity *= hashMap->extendRatio;
|
|
|
|
hashMap->capacity *= hashMap->extendRatio;
|
|
|
|
hashMap->buckets = (Pair **)malloc(sizeof(Pair *) * hashMap->capacity);
|
|
|
|
hashMap->buckets = (Pair **)calloc(hashMap->capacity, sizeof(Pair *));
|
|
|
|
hashMap->size = 0;
|
|
|
|
hashMap->size = 0;
|
|
|
|
// 将键值对从原哈希表搬运至新哈希表
|
|
|
|
// 将键值对从原哈希表搬运至新哈希表
|
|
|
|
for (int i = 0; i < oldCapacity; i++) {
|
|
|
|
for (int i = 0; i < oldCapacity; i++) {
|
|
|
|