From 19aafc0b4ef8a0ccbbe8d2db736ed59b18f54667 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Wed, 3 Sep 2008 04:16:25 +0000 Subject: [PATCH] changes --- Robust/src/Runtime/chash.c | 9 ++++++--- Robust/src/Runtime/chash.h | 13 ++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Robust/src/Runtime/chash.c b/Robust/src/Runtime/chash.c index d49c749a..b8cfd41e 100644 --- a/Robust/src/Runtime/chash.c +++ b/Robust/src/Runtime/chash.c @@ -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 diff --git a/Robust/src/Runtime/chash.h b/Robust/src/Runtime/chash.h index c8bf4416..d85fbd03 100644 --- a/Robust/src/Runtime/chash.h +++ b/Robust/src/Runtime/chash.h @@ -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 -- 2.34.1