Skip to content

Hash Tables - Evan Carlstrom#148

Open
ecarlstrom wants to merge 16 commits into
bloominstituteoftechnology:masterfrom
ecarlstrom:master
Open

Hash Tables - Evan Carlstrom#148
ecarlstrom wants to merge 16 commits into
bloominstituteoftechnology:masterfrom
ecarlstrom:master

Conversation

@ecarlstrom

Copy link
Copy Markdown

No description provided.

@codejoncode codejoncode left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ecarlstrom

Copy link
Copy Markdown
Author

Fixed, thanks!

@codejoncode codejoncode left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 */
  }
  1. Create a variable that stores the current Pair * from ht->storage[i]
  2. 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.
  3. 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.

@codejoncode codejoncode left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good Evan I don't see anything that strikes me as a problem currently.

@ecarlstrom

Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants