Skip to content

Kevin Sooter - Hash-Tables#147

Open
kevin-sooter wants to merge 12 commits into
bloominstituteoftechnology:masterfrom
kevin-sooter:master
Open

Kevin Sooter - Hash-Tables#147
kevin-sooter wants to merge 12 commits into
bloominstituteoftechnology:masterfrom
kevin-sooter:master

Conversation

@kevin-sooter

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.

Great start Kevin. In your create_function ht->storage = calloc(capacity, sizeof(char *)) We need Pair struct pointers so ht->storage = calloc(capacity, sizeof(Pair *))

This is what you should have.

@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.

if (ht->storage[target_index] != NULL)
  {                                                          // If the node at the index is not empty
    printf("You're overwriting an existing value value!\n"); // give warning
    destroy_pair(ht->storage[target_index]);                 // free up the memory at that index
    ht->storage[target_index] = new_pair;                    // insert new node into target index
  }

Your condition has a good base we want to destroy the pair if its not null however we want to print out a error if we overwrite so we want to do a check for if (strcmp(ht->storage[target_index]->key, key) != 0) meaning if the key that is there is different than the key we receive in the function. If the key is the same then we are just performing a update if its different we are overwriting what's there. This would be a nested conditional inside of the one you already have.

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