Skip to content

Sean Flannigan - Hash-Tables#151

Open
sean-one wants to merge 10 commits into
bloominstituteoftechnology:masterfrom
sean-one:master
Open

Sean Flannigan - Hash-Tables#151
sean-one wants to merge 10 commits into
bloominstituteoftechnology:masterfrom
sean-one:master

Conversation

@sean-one

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 Sean one thing we are leaving out in the create function you have ht->storage = calloc(capacity, sizeof(Pair));

Since the it is a pointer we will need ht->storage = calloc(capacity, sizeof(Pair *));

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

ht->storage[hashed] = strdup(insert_pair);

we can just use ht->storage[hashed] = pair; since the create_pair function is strdup for us.

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

For your hash_table remove we don't need the for loop

  1. get the index using the hash function.
  2. create a Pair *current_pair that will equal the ht->storage[index] (you will get the index back from the hash function)
  3. if the index of storage does not equal NULL then destroy the pair using the destroy pair function
  4. Then update the ht->storage[index] to NULL

Please reach out if the steps above cause you any trouble to implement.

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

for your retrieve let's return the value instead current_pair->key; update to current_pair->value;

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

Sean for your hash_table_insert function
Not sure if you are passing the tests however we can keep the while loop simple.

while (current_pair != NULL && strcmp(current_pair->key, key) != 0) {
    last_pair = current_pair;
    current_pair = last_pair->next;
  }```

Outside of the loop you can then check if current_pair is NULL     if it is not  update current_pair->value to the value we received in the function   else    create a new pair and have that equal  `ht->storage[index]`  then set the `ht->storage[index]` to equal your new pair. 

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