}
//Store objects and their pointers into hash
-INLINE void cInsert(ctable_t *table, unsigned int key, void *val) {
+INLINE void cInsert(ctable_t *table, void * key, void *val) {
unsigned int newsize;
int index;
cnode_t *ptr, *node;
- ptr = &table->table[(key & table->mask)>>2];
+ ptr = &table->table[(((unsigned int)key) & table->mask)>>2];
if (ptr->key==0) {
ptr->key=key;
ptr->val=val;
}
// Search for an address for a given oid
-INLINE void * cSearch(ctable_t *table, unsigned int key) {
+INLINE void * cSearch(ctable_t *table, void * key) {
//REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE
- cnode_t *node = &table->table[(key & table->mask)>>2];
+ cnode_t *node = &table->table[(((unsigned int)key) & table->mask)>>2];
while(node != NULL) {
if(node->key == key) {
return NULL;
}
-unsigned int cRemove(ctable_t *table, unsigned int key) {
+unsigned int cRemove(ctable_t *table, void * key) {
int index;
cnode_t *curr, *prev;
cnode_t *ptr, *node;
ptr = table->table;
- index =(key & table->mask)>>2;
+ index =(((unsigned int)key) & table->mask)>>2;
curr = &ptr[index];
for (; curr != NULL; curr = curr->next) {
if (curr->key == key) { // Find a match in the hash table
table->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 cnode_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 cnode_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);
}
return 0;
}
continue;
while(curr!=NULL) {
cnode_t * next = curr->next;
- int index =(curr->key & mask)>>2;
+ int index =(((unsigned int)curr->key) & mask)>>2;
cnode_t * newnode=&ntable[index];
-
+
if(newnode->key==0) {
- newnode->key=curr->key;
- newnode->val=curr->val;
- newnode->lnext=last;
- last=newnode;
+ newnode->key=curr->key;
+ newnode->val=curr->val;
+ newnode->lnext=last;
+ last=newnode;
} else {
- cnode_t *tmp=malloc(sizeof(cnode_t));
- tmp->next=newnode->next;
- newnode->next=tmp;
- tmp->key=curr->key;
- tmp->val=curr->val;
- tmp->lnext=last;
- last=tmp;
- }
+ cnode_t *tmp=malloc(sizeof(cnode_t));
+ tmp->next=newnode->next;
+ newnode->next=tmp;
+ tmp->key=curr->key;
+ tmp->val=curr->val;
+ tmp->lnext=last;
+ last=tmp;
+ }
if (isfirst) {
- isfirst=0;
+ isfirst=0;
} else {
- free(curr);
+ free(curr);
}
curr = next;
}
cnode_t *ptr, *curr, *next;
ptr = ctable->table;
- for(i=0 ; i<ctable->size ; i++) {
+ for(i=0; i<ctable->size; i++) {
curr = &ptr[i];
- isFirst = 1 ;
+ isFirst = 1;
while(curr != NULL) {
next = curr->next;
if(isFirst != 1) {
- free(curr);
+ free(curr);
}
isFirst = 0;
curr = next;