Sean Flannigan - Hash-Tables#151
Conversation
codejoncode
left a comment
There was a problem hiding this comment.
Great start Sean one thing we are leaving out in the create function you have ht->storage = calloc(capacity, sizeof(Pair));
Since the it is a pointer we will need ht->storage = calloc(capacity, sizeof(Pair *));
codejoncode
left a comment
There was a problem hiding this comment.
ht->storage[hashed] = strdup(insert_pair);
we can just use ht->storage[hashed] = pair; since the create_pair function is strdup for us.
codejoncode
left a comment
There was a problem hiding this comment.
For your hash_table remove we don't need the for loop
- get the index using the hash function.
- create a Pair *current_pair that will equal the ht->storage[index] (you will get the index back from the hash function)
- if the index of storage does not equal NULL then destroy the pair using the destroy pair function
- Then update the ht->storage[index] to NULL
Please reach out if the steps above cause you any trouble to implement.
codejoncode
left a comment
There was a problem hiding this comment.
for your retrieve let's return the value instead current_pair->key; update to current_pair->value;
codejoncode
left a comment
There was a problem hiding this comment.
Sean for your hash_table_insert function
Not sure if you are passing the tests however we can keep the while loop simple.
while (current_pair != NULL && strcmp(current_pair->key, key) != 0) {
last_pair = current_pair;
current_pair = last_pair->next;
}```
Outside of the loop you can then check if current_pair is NULL if it is not update current_pair->value to the value we received in the function else create a new pair and have that equal `ht->storage[index]` then set the `ht->storage[index]` to equal your new pair.
No description provided.