Skip to content

init commit Toua#156

Open
txiong000 wants to merge 8 commits into
bloominstituteoftechnology:masterfrom
txiong000:master
Open

init commit Toua#156
txiong000 wants to merge 8 commits into
bloominstituteoftechnology:masterfrom
txiong000:master

Conversation

@txiong000

Copy link
Copy Markdown

No description provided.


BasicHashTable *ht = malloc(sizeof(BasicHashTable));
ht->capacity = capacity;
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 this is sizeof(Pair). If you wanted the size of the pointer, it would be sizeof(*Pair).

unsigned int index = hash(key, ht->capacity);
if (ht->storage[index]) {
printf("This value will be overwriting");
destroy_pair(ht->storage[index]);

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 don't know if this is necessary but it doesn't hurt to do it.

{

unsigned int index = hash(key, ht->capacity);
if (ht->storage[index]) {

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 think it would be best to check if this is not NULL.

unsigned int index = hash(key, ht->capacity);
if (ht->storage[index]){
return ht->storage[index]->value;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This looks great!

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