//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;
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;
}
// 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++;
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;
}
//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;
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;
}