Hash Tables - Evan Carlstrom#148
Conversation
… collision handling yet, to be added later.
codejoncode
left a comment
There was a problem hiding this comment.
Good job so far Evan ht->storage = calloc(capacity, sizeof(char *)); from your create function needs to be ht->storage = calloc(capacity, sizeof(Pair *)); because your storage will store the Pair pointers.
…per Jonathan's note
|
Fixed, thanks! |
There was a problem hiding this comment.
You have a good solid base with your error handling condition in the insert function
if(ht->storage[i]) {
fprintf(stderr, "Indexing error: there is a current value being overwritten.\n");
free(ht->storage[i]); /* if ht->storage[i] exists, this message comes up and the memory at index i is freed */
}
- Create a variable that stores the current Pair * from ht->storage[i]
- inside of your current conditional check lets perform a new conditional check for if key(the one we receive into the function) ==(only use strcmp instead of ==) to your current stored pair->key. If it does not equal 0 then print out your warning.
- Wipe out the free expression and outside of the nested conditional lets destroy the current stored pair using the destroyed pair function.
The nested condition is checking whether or not the key is the same if it is not this would be where we are overwriting, tomorrow we will handle collisions.
…urning the memory index (ht->storage[i]) rather than the value (ht->storage[i]->value), added the value.
…VP. Going back to look at my hash_table_insert function and edit it based on Jonathan's notes.
…ctly with data returning properly
…re I can see if all tests are passing
…ssing, day 2 MVP complete.
codejoncode
left a comment
There was a problem hiding this comment.
Looks pretty good Evan I don't see anything that strikes me as a problem currently.
|
Today's guided demo definitely helped with implementing the functions, I felt much more confident starting out than I did yesterday. I'm going to look at my basic hashtables code because there were 2 or 3 from there that passed tests but weren't written efficiently. |
No description provided.