changes
authorbdemsky <bdemsky>
Wed, 3 Sep 2008 04:16:25 +0000 (04:16 +0000)
committerbdemsky <bdemsky>
Wed, 3 Sep 2008 04:16:25 +0000 (04:16 +0000)
Robust/src/Runtime/chash.c
Robust/src/Runtime/chash.h

index d49c749acb9a768bad8bbcd700bd55b9050a2c9f..b8cfd41ec8e7982b6496e3a4a418cf6afadf3d04 100644 (file)
@@ -1,6 +1,8 @@
 #include "chash.h"
 #define INLINE    inline __attribute__((always_inline))
 
+void crehash(ctable_t *table);
+
 ctable_t *cCreate(unsigned int size, float loadfactor) {
   ctable_t *ctable;
   cnode_t *nodes;
@@ -20,9 +22,10 @@ ctable_t *cCreate(unsigned int size, float loadfactor) {
 
   ctable->table = nodes;
   ctable->size = size;
-  ctable->mask = (size << 1)-1;
+  ctable->mask = (size << 2)-1;
   ctable->numelements = 0; // Initial number of elements in the hash
   ctable->loadfactor = loadfactor;
+  ctable->head=NULL;
 
   return ctable;
 }
@@ -121,7 +124,7 @@ unsigned int cResize(ctable_t *table, unsigned int newsize) {
 
   table->table = node;          //Update the global hashtable upon resize()
   table->size = newsize;
-  table->mask = (newsize << 1)-1;
+  table->mask = (newsize << 2)-1;
   table->numelements = 0;
 
   for(i = 0; i < oldsize; i++) {                        //Outer loop for each bin in hash table
@@ -133,7 +136,7 @@ unsigned int cResize(ctable_t *table, unsigned int newsize) {
       }
       next = curr->next;
 
-      index =(key & table->mask)>>2;
+      index =(curr->key & table->mask)>>2;
 #ifdef DEBUG
       printf("DEBUG(resize) -> index = %d, key = %d, val = %x\n", index, curr->key, curr->val);
 #endif
index c8bf44162fb2c2ef043ce8590cca962983d1f532..d85fbd03871f2bab218bf5ca7e8be9df26ab9e85 100644 (file)
@@ -8,6 +8,7 @@ typedef struct cnode {
   unsigned int key;
   void *val;       //this can be cast to another type or used to point to a larger structure
   struct cnode *next;
+  struct cnode *lnext;
 } cnode_t;
 
 typedef struct ctable {
@@ -16,15 +17,17 @@ typedef struct ctable {
   unsigned int mask;
   unsigned int numelements;
   float loadfactor;
+  struct cnode *listhead;  
 } ctable_t;
 
 /* Prototypes for hash*/
 ctable_t *cCreate(unsigned int size, float loadfactor);
-unsigned int cInsert(ctable_t *table, unsigned int key, unsigned int val);
-unsigned int cSearch(chashtable_t *table, unsigned int key); //returns val, NULL if not found
-unsigned int cRemove(chashtable_t *table, unsigned int key); //returns -1 if not found
-unsigned int cResize(chashtable_t *table, unsigned int newsize);
-void cDelete(chashtable_t *table);
+unsigned int cInsert(ctable_t *table, unsigned int key, void * val);
+void * cSearch(ctable_t *table, unsigned int key); //returns val, NULL if not found
+unsigned int cRemove(ctable_t *table, unsigned int key); //returns -1 if not found
+unsigned int cResize(ctable_t *table, unsigned int newsize);
+void cDelete(ctable_t *table);
+void crehash(ctable_t *table);
 /* end hash */
 
 #endif