Skip to content

hashtables ✨#160

Open
sumi419 wants to merge 2 commits into
bloominstituteoftechnology:masterfrom
sumi419:master
Open

hashtables ✨#160
sumi419 wants to merge 2 commits into
bloominstituteoftechnology:masterfrom
sumi419:master

Conversation

@sumi419

@sumi419 sumi419 commented Feb 28, 2019

Copy link
Copy Markdown

No description provided.

Comment thread basic_hashtable/b_hashtables.c Outdated
{
BasicHashTable *ht;
BasicHashTable *ht = malloc(sizeof(BasicHashTable));
ht->storage = calloc(capacity, sizeof(Pair *));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I believe you want this to be sizeof(Pair).

if (ht->storage[hashedkey] != NULL)
{
printf("Overwriting a value.");
destroy_pair(ht->storage[hashedkey]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm not sure that this is entirely necessary, but I guess it doesn't hurt to do it.

{

unsigned int hashedkey = hash(key, ht->capacity);
if (ht->storage[hashedkey] != NULL)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice NULL check here.

destroy_pair(ht->storage[i]);
}
free(ht->storage);
free(ht);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Very well done!

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