#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;
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;
}
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
}
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
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 {
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