Last active
May 28, 2016 16:12
-
-
Save teldridge11/7f2b5d01ee8a9e140c16414b92caf10b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void hashMapPut(HashMap* map, const char* key, int value) { | |
// FIXME: implement | |
float load = hashMapTableLoad(map); | |
if(load >= MAX_TABLE_LOAD) { | |
resizeTable(map, hashMapCapacity(map)); | |
} | |
int i = HASH_FUNCTION(key) % map->capacity; | |
HashLink *cur = map->table[i]; | |
while(cur) { | |
if(strcmp(cur->key, key) == 0) { | |
cur->value = value; | |
return; | |
} | |
cur = cur->next; | |
} | |
map->table[i] = hashLinkNew(key, value, NULL); | |
map->size++; | |
} | |
void resizeTable(HashMap* map, int capacity) | |
{ | |
// FIXME: implement | |
struct HashMap *newMap = hashMapNew((5 * map->size)); | |
//go through old hash table and add all of its values to the new hash table | |
for(int i = 0; i < map->capacity; ++i) { | |
struct HashLink *tmp = map->table[i]; | |
while(tmp){ | |
hashMapPut(newMap, tmp->key, tmp->value); | |
tmp = tmp->next; | |
} | |
} | |
//hashMapDelete(map); | |
*map = *newMap; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment