From f67138289a48515f6e0738b9be3cf557c705b821 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Sun, 22 Feb 2009 11:43:32 +0000 Subject: [PATCH] few more changes --- Robust/src/Runtime/DSTM/interface/clookup.c | 19 +++++++++--------- Robust/src/Runtime/DSTM/interface/mlookup.c | 17 +++++++++------- Robust/src/Runtime/DSTM/interface/prelookup.c | 20 ++++++++++--------- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/Robust/src/Runtime/DSTM/interface/clookup.c b/Robust/src/Runtime/DSTM/interface/clookup.c index 2da79f8d..05d9401e 100644 --- a/Robust/src/Runtime/DSTM/interface/clookup.c +++ b/Robust/src/Runtime/DSTM/interface/clookup.c @@ -36,25 +36,22 @@ static INLINE unsigned int chashFunction(chashtable_t *table, unsigned int key) //Store objects and their pointers into hash void chashInsert(chashtable_t *table, unsigned int key, void *val) { - unsigned int newsize; - int index; - chashlistnode_t *ptr, *node; + chashlistnode_t *ptr; if(table->numelements > (table->threshold)) { //Resize - newsize = table->size << 1; + unsigned int newsize = table->size << 1; chashResize(table,newsize); } - index = (key & table->mask) >>1; - ptr = &table->table[index]; + ptr = &table->table[(key&table->mask)>>1]; table->numelements++; if(ptr->key==0) { ptr->key=key; ptr->val=val; } else { // Insert in the beginning of linked list - node = calloc(1, sizeof(chashlistnode_t)); + chashlistnode_t * node = calloc(1, sizeof(chashlistnode_t)); node->key = key; node->val = val; node->next = ptr->next; @@ -158,13 +155,17 @@ unsigned int chashResize(chashtable_t *table, unsigned int newsize) { if (!isfirst) { free(curr); } - } else if (isfirst) { + }/* + NOTE: Add this case if you change this... + This case currently never happens because of the way things rehash.... + else if (isfirst) { chashlistnode_t *newnode= calloc(1, sizeof(chashlistnode_t)); newnode->key = curr->key; newnode->val = curr->val; newnode->next = tmp->next; tmp->next=newnode; - } else { + } */ + else { curr->next=tmp->next; tmp->next=curr; } diff --git a/Robust/src/Runtime/DSTM/interface/mlookup.c b/Robust/src/Runtime/DSTM/interface/mlookup.c index 10792450..40084563 100644 --- a/Robust/src/Runtime/DSTM/interface/mlookup.c +++ b/Robust/src/Runtime/DSTM/interface/mlookup.c @@ -29,18 +29,16 @@ unsigned int mhashFunction(unsigned int key) { // Insert value and key mapping into the hash table void mhashInsert(unsigned int key, void *val) { - unsigned int newsize; - int index; mhashlistnode_t *ptr, *node; pthread_mutex_lock(&mlookup.locktable); if (mlookup.numelements > mlookup.threshold) { //Resize Table - newsize = mlookup.size << 1; + unsigned int newsize = mlookup.size << 1; mhashResize(newsize); } - index = (key & mlookup.mask) >>1; - ptr = &mlookup.table[index]; + + ptr = &mlookup.table[(key & mlookup.mask) >>1]; mlookup.numelements++; @@ -154,13 +152,18 @@ unsigned int mhashResize(unsigned int newsize) { tmp->val=curr->val; if (!isfirst) free(curr); - } else if (isfirst) { + } /* + + NOTE: Add this case if you change this... + This case currently never happens because of the way things rehash.... +else if (isfirst) { mhashlistnode_t *newnode = calloc(1, sizeof(mhashlistnode_t)); newnode->key = curr->key; newnode->val = curr->val; newnode->next = tmp->next; tmp->next=newnode; - } else { + } */ + else { curr->next=tmp; tmp->next=curr; } diff --git a/Robust/src/Runtime/DSTM/interface/prelookup.c b/Robust/src/Runtime/DSTM/interface/prelookup.c index 9f181bca..15aeaad8 100644 --- a/Robust/src/Runtime/DSTM/interface/prelookup.c +++ b/Robust/src/Runtime/DSTM/interface/prelookup.c @@ -43,26 +43,24 @@ unsigned int prehashFunction(unsigned int key) { //Store oids and their pointers into hash void prehashInsert(unsigned int key, void *val) { - unsigned int newsize; - int index; - prehashlistnode_t *ptr, *node; + prehashlistnode_t *ptr; pthread_mutex_lock(&pflookup.lock); if(pflookup.numelements > (pflookup.threshold)) { //Resize - newsize = pflookup.size << 1; + unsigned int newsize = pflookup.size << 1; prehashResize(newsize); } - index = (key & pflookup.mask)>>1; - ptr = &pflookup.table[index]; + + ptr = &pflookup.table[(key & pflookup.mask)>>1]; pflookup.numelements++; if(ptr->key==0) { ptr->key = key; ptr->val = val; } else { // Insert in the beginning of linked list - node = calloc(1, sizeof(prehashlistnode_t)); + prehashlistnode_t * node = calloc(1, sizeof(prehashlistnode_t)); node->key = key; node->val = val ; node->next = ptr->next; @@ -162,13 +160,17 @@ unsigned int prehashResize(unsigned int newsize) { tmp->val=curr->val; if (!isfirst) free(curr); - } else if (isfirst) { + } /* + NOTE: Add this case if you change this... + This case currently never happens because of the way things rehash.... +else if (isfirst) { prehashlistnode_t * newnode = calloc(1, sizeof(prehashlistnode_t)); newnode->key = curr->key; newnode->val = curr->val; newnode->next = tmp->next; tmp->next=newnode; - } else { + } */ + else { curr->next=tmp->next; tmp->next=curr; } -- 2.34.1