if (curr->key == key) { // Find a match in the hash table
mlookup.numelements--; // Decrement the number of elements in the global hashtable
if ((curr == &ptr[index]) && (curr->next == NULL)) { // Delete the first item inside the hashtable with no linked list of mhashlistnode_t
- curr->key = 0;
- curr->val = NULL;
+ curr->key = 0;
+ curr->val = NULL;
} else if ((curr == &ptr[index]) && (curr->next != NULL)) { //Delete the first item with a linked list of mhashlistnode_t connected
- curr->key = curr->next->key;
- curr->val = curr->next->val;
- node = curr->next;
- curr->next = curr->next->next;
- free(node);
+ curr->key = curr->next->key;
+ curr->val = curr->next->val;
+ node = curr->next;
+ curr->next = curr->next->next;
+ free(node);
} else { // Regular delete from linked listed
- prev->next = curr->next;
- free(curr);
+ prev->next = curr->next;
+ free(curr);
}
pthread_mutex_unlock(&mlookup.locktable);
return 0;
mhashlistnode_t *tmp,*next;
if ((key=curr->key) == 0) { //Exit inner loop if there the first element for a given bin/index is NULL
- break; //key = val =0 for element if not present within the hash table
+ break; //key = val =0 for element if not present within the hash table
}
next = curr->next;
index = (key & mask) >>1;
// Insert into the new table
if(tmp->key ==0) {
- tmp->key=curr->key;
- tmp->val=curr->val;
- if (!isfirst)
- free(curr);
+ tmp->key=curr->key;
+ tmp->val=curr->val;
+ if (!isfirst)
+ free(curr);
} /*
- NOTE: Add this case if you change this...
- This case currently never happens because of the way things rehash....
- else if (isfirst) {
- mhashlistnode_t *newnode = calloc(1, sizeof(mhashlistnode_t));
- newnode->key = curr->key;
- newnode->val = curr->val;
- newnode->next = tmp->next;
- tmp->next=newnode;
- } */
+ NOTE: Add this case if you change this...
+ This case currently never happens because of the way things rehash....
+ else if (isfirst) {
+ mhashlistnode_t *newnode = calloc(1, sizeof(mhashlistnode_t));
+ newnode->key = curr->key;
+ newnode->val = curr->val;
+ newnode->next = tmp->next;
+ tmp->next=newnode;
+ } */
else {
- curr->next=tmp->next;
- tmp->next=curr;
+ curr->next=tmp->next;
+ tmp->next=curr;
}
isfirst = 0;
curr = next;
if (mlookup.table[i].key != 0) {
curr = &mlookup.table[i];
while (curr != NULL) {
- keys[keyindex++] = curr->key;
- curr = curr->next;
+ keys[keyindex++] = curr->key;
+ curr = curr->next;
}
}
}