fixes on analyses to compile the eyetracking benchmark
[IRC.git] / Robust / src / Runtime / chash.c
index 6c98d94f360500a3766f91fc2eebb6bce9d71cff..3f3a11ac2705b10497bc590b64cec12b088e2b89 100644 (file)
@@ -33,12 +33,12 @@ ctable_t *cCreate(unsigned int size, float loadfactor) {
 }
 
 //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;
@@ -63,9 +63,9 @@ INLINE void cInsert(ctable_t *table, unsigned int key, void *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) {
@@ -76,30 +76,30 @@ INLINE void * cSearch(ctable_t *table, unsigned int 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;
     }
@@ -128,27 +128,27 @@ unsigned int cResize(ctable_t *table, unsigned int newsize) {
       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;
     }
@@ -164,13 +164,13 @@ void cDelete(ctable_t *ctable) {
   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;